我想保持设备开启,并避免在没有用户活动的情况下从内存中卸载我的应用程序.像服务一样的东西.我制作了类似如何检查网络是否可用于Android和iOS(Delphi XE5)的模块,但是当我运行SetWakeLock时系统崩溃:
unit Android.PowerManager;
interface
function SetWakeLock : boolean;
procedure ReleaseWakeLock;
implementation
uses
System.SysUtils,
Androidapi.JNI,
Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.JavaTypes,
FMX.Helpers.Android;
type
JPowerManager = interface;
JWakeLock = interface;
JWakeLockClass = interface(JObjectClass)
['{4CF7A13D-15A9-4DEE-8CA7-66600C188CB7}']
end;
[JavaSignature('android/os/PowerManager/WakeLock')]
JWakeLock = interface(JObject)
['{55983EDC-782F-490A-BF0C-12207EB7829E}']
{Methods}
procedure acquire; cdecl;
procedure release; cdecl;
function isHeld: Boolean; cdecl;
end;
TJWakeLock = class(TJavaGenericImport<JWakeLockClass, JWakeLock>) end;
JPowerManagerClass = interface(JObjectClass)
['{B127DD4E-1DA6-49E7-98BA-5966DC7E26FA}']
end;
[JavaSignature('android/os/PowerManager')]
JPowerManager = interface(JObject)
['{241C3B3D-3DF0-489B-A33E-3CD7F5D26313}']
{Methods}
function newWakeLock(levelAndFlags: integer; tag: JString): JWakeLock; cdecl;
end;
TJPowerManager = class(TJavaGenericImport<JPowerManagerClass, JPowerManager>) end;
function …Run Code Online (Sandbox Code Playgroud) 我在表单设置上有一个TIdUDPServer,默认端口和广播模式已启用,无法在Android下接收任何内容.
相同的代码在iOS下工作正常,但如果我重新定位Android我没有收到任何东西.
有没有我缺少的技巧.我已经检查了"用户权限"并打开了我认为可能会影响这一切的所有内容,但是没有运气让它运行起来.
马丁,提前谢谢
我编写了以下代码来计算用户输入时的行数和字符数.但它有一个问题,它在用户输入第一个字符后开始计数,当他按下退格键时,它会增加计数器,然后开始减少它.
procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
begin
Text1.Text := 'Lines: ' + IntToStr (Memo1.Lines.Count);
Text2.Text := 'Characters: ' + IntToStr (Length(Memo1.Text));
end;
Run Code Online (Sandbox Code Playgroud) 我已经更新了我的XE5 Update1的几个应用程序.从那时起,ShowMessage经常触发访问冲突.这种情况发生在几个应用程 如果我用一个简单的表单替换ShowMessage,那么AV就不见了.所以这显然是ShowMessage的罪魁祸首.
AV出现在函数TaskDialogIndirect的WinApi.CommCtrl.pas中(参见下面的标记行):
function TaskDialogIndirect(const pTaskConfig: TTaskDialogConfig;
pnButton: PInteger; pnRadioButton: PInteger; pfVerificationFlagChecked: PBOOL): HRESULT;
begin
if Assigned(_TaskDialogIndirect) then
Result := _TaskDialogIndirect(pTaskConfig, pnButton, pnRadioButton,
pfVerificationFlagChecked) // <====== HERE ==========
else
begin
InitComCtl;
Result := E_NOTIMPL;
if ComCtl32DLL <> 0 then
begin
@_TaskDialogIndirect := GetProcAddress(ComCtl32DLL, 'TaskDialogIndirect');
if Assigned(_TaskDialogIndirect) then
Result := _TaskDialogIndirect(pTaskConfig, pnButton, pnRadioButton,
pfVerificationFlagChecked)
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
发生异常时的堆栈跟踪:
:671cab85 ; D:\Development\DelphiLibs\madCollection\madExcept\Dlls\madExcept32.dll
:671cabe2 ; D:\Development\DelphiLibs\madCollection\madExcept\Dlls\madExcept32.dll
:671ca755 madExcept32.ThisIsNoLeak + 0x29
:004aa9d7 ThisIsNoLeak + $F
:004a9412 HookedCreateThread + $82
:769613a2 msvcrt._beginthreadex + 0x74 …Run Code Online (Sandbox Code Playgroud) 我试图隐藏运行时和 进程发送shell命令到root电话我不明白为什么我有分段错误.在互联网上,我发现java代码如:
Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot now"});` for reboot of the phone or `Runtime.getRuntime().exec("su");
Run Code Online (Sandbox Code Playgroud)
对于linux root权限.
我试着在转换后只用函数发送"su"命令,但我觉得我错了......我认为一个可能的问题可能是来自java类型的Jstring转换数组.
unit Androidapi.JNI.Root;
interface
procedure AskRoot;
implementation
uses System.SysUtils,
Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.JavaTypes,
FMX.Helpers.Android;
type
JProcess = interface;
JRuntime = interface;
//----------------------------------JProcess----------------------
JProcessClass = interface(JObjectClass)
['{7BFD2CCB-89B6-4382-A00B-A7B5BB0BC7C9}']
end;
[JavaSignature('java/lang/Process')]
JProcess = interface(JObject)
['{476414FD-570F-4EDF-B678-A2FE459EA6EB}']
{Methods}
procedure destroy; cdecl;
function exitValue:integer;cdecl;
function getErrorStream:JInputStream; cdecl;
function getInputStream:JOutputStream; cdecl;
function waitFor:integer;cdecl;
end;
TJProcess = class(TJavaGenericImport<JProcessClass, JProcess>) end;
//----------------------------------Jruntime----------------------
JRuntimeClass = interface(JObjectClass)
['{3F2E949D-E97C-4AD8-B5B9-19CB0A6A29F3}']
{costant}
end;
[JavaSignature('java/lang/Runtime')]
JRuntime = interface(JObject)
['{C097A7EC-677B-4BCB-A4BD-7227160750A5}'] …Run Code Online (Sandbox Code Playgroud) 当RichEdit控件成为其他控件的父文件时,它会停止绘制文本.
这是一个功能还是一个bug?是否有可能使RichEdit成为其他控件的父级?
看看下一个应用:
- Form1.dfm ---
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 282
ClientWidth = 418
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 24
Top = 8
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object RichEdit1: TRichEdit
Left …Run Code Online (Sandbox Code Playgroud) 我使用一个简单的命令从文件中获取文件日期,但一直得到错误的日期.
在我的电脑上,我看了看日期是14/3/2014.但是当我运行命令时,无论我尝试什么文件,我都会得到30/12/1999,它会保持相同的返回日期.
我试过了
BackupFileDate:=FileAge(S);;
originalfiledate:=FileAge(fileName);
Run Code Online (Sandbox Code Playgroud)
和
BackupFileDate:=GetFileModDate(S);
originalfiledate:=GetFileModDate(Filename);
function GetFileModDate(filename : string) : TDateTime;
var
F : TSearchRec;
begin
FindFirst(filename,faAnyFile,F);
Result := F.TimeStamp;
//Result := F.Time;
FindClose(F);
end;
Run Code Online (Sandbox Code Playgroud)
两者都有相同的结果.PS:BackupFileDate和originalfiledate现在都被定义为TDate,我已经尝试过TDateTime,结果相同.
我想获得上次编辑文件的日期和时间.
我在使用指定的initialdir启动OpenDialog窗口时遇到问题.我现在拥有的是什么
procedure TForm1.fileMenuLoadClick(Sender: TObject);
begin
SetCurrentDir(StartDir);
SetCurrentDir('Cases');
OpenDialog.Filename := '';
OpenDialog.InitialDir := GetCurrentDir;
OpenDialog.Filter := 'Sparfiler (.dat)|*.dat';
// -------------------------------
if OpenDialog.Execute then
begin
GeometryClear;
DerobModel.Filename := OpenDialog.Filename;
DerobModel.Open;
pressed := True;
SetCurrentDir('../');
DerobModel.HouseProperties.StringValue['CaseDir'] := GetCurrentDir;
DerobModel.HouseProperties.StringValue['StartDir'] := StartDir;
SetCurrentDir(StartDir);
UpdateGeometryPanel;
mainUpdateComboBox;
UpdatePropertiesPanel;
UpdateEnergyPanel;
UpdateAbsorption;
UpdateClimatePanel;
UpdateClimate;
mainHide;
Geometry.IsSelected := True;
GeometryPanel.Visible := True;
TreeView1.Enabled := True;
TreeView1.HitTest := True;
DerobModel.HouseProperties.BoolValue['GlazeChange'] := False;
end;
Run Code Online (Sandbox Code Playgroud)
运行此代码时,它会一直打开我打开的最后一个文件的文件夹.我读到解决方案是清除OpenDialog的FileName属性,但它不起作用.然而有趣的是,它正在处理来自我的应用程序的先前版本的代码.
procedure TForm1.fileMenuLoadClick(Sender: TObject);
begin
SetCurrentDir(StartDir);
SetCurrentDir('Cases');
OpenDialog.Filename := '';
OpenDialog.InitialDir := GetCurrentDir;
OpenDialog.Filter := 'Sparfiler (.dat)|*.dat'; …Run Code Online (Sandbox Code Playgroud) 我试图删除我的FDTable组件中的所有记录,使用,
mytable.Delete;
但没有记录被删除.
任何人都可以建议我删除FdTable中的所有记录.
编辑
我用这种方式修改了它,
for i := mytable.RecordCount - 1 downto 0 do
begin
mytable.Delete;
end;
mytable.Refresh;
Run Code Online (Sandbox Code Playgroud)
但这需要很多时间,因为我的fdtable中有很多行.
使用TList作为记录的容器.在应用程序中,TList添加和删除大量记录.但之后delete,财产capacity 永远不会减少,内存也不会被释放.怎么解决这个问题?简单的代码示例:
type
TMyRecord = record
Num : integer;
Str : String
end;
var
MyRecord : TMyRecord;
MyList :TList<TMyRecord>;
MyList := TList<TMyRecord>.Create;
MyRecord.Num := 1;
MyRecord.Str := 'abc';
for i := 0 to 63 do
begin
MyList.Add(MyRecord);
end;
Memo1.Lines.Add('Before deleting');
Memo1.Lines.Add('Count='+IntToStr(MyList.Count));
Memo1.Lines.Add('Capacity='+IntToStr(MyList.Capacity));
for i := 0 to 59 do
begin
MyList.Delete(0);
end;
MyList.Pack; // Here need to somehow free the memory.
Memo1.Lines.Add('After deleting');
Memo1.Lines.Add('Count='+IntToStr(MyList.Count));
Memo1.Lines.Add('Capacity='+IntToStr(MyList.Capacity));
Run Code Online (Sandbox Code Playgroud) delphi ×10
delphi-xe5 ×10
android ×3
firedac ×1
firemonkey ×1
indy ×1
java ×1
linux ×1
richedit ×1