小编Mar*_*cel的帖子

如何使用Delphi从Thread更新GUI

我正在使用Delphi匿名线程来执行代码.在线程的中间,必须进行一些GUI更新,一些标签更改等.

如果我从线程内部执行此操作,则会发生更改,但一旦线程停止.他们消失了,然后应用程序给我旧的窗口处理程序错误...(这是预期的)

System Error. Code:1400. Invalid window handle

我尝试使用该Syncronize(updateui);方法来执行更改(将它们移动到一个单独的函数),但是我在syncronize上得到一个错误,E2066 Missing operator or semicolon这对我来说根本没有意义......

我一页又一页地搜索过,他们似乎都这么称呼它,但是当我这样做时,我得到了上述错误......

我说错了吗?

码:

TThread.CreateAnonymousThread(
procedure
 begin
 main.Enabled:=false;
 Loading.show;
 label52.caption:=getfieldvalue(datalive.users,'users','credit_amount','user_id',user_id );
 CoInitialize(nil);
   if (length(maskedit1.Text)=maskedit1.MaxLength) and (pingip(serverip)=true) then
    begin
       if (strtofloat(label52.caption)>0) then
        begin
           ....do some work....

           Synchronize(updateui);
        end
       else Showmessage('Insufficient Funds. Please add funds to continue.');
    end
   else if (length(maskedit1.Text)<>maskedit1.MaxLength) then
    begin
     Showmessage('ID Number not long enough.');
    end
   else
    begin
     Showmessage('Could not connect to the server. Please check your internet connection and try again.');
    end; …
Run Code Online (Sandbox Code Playgroud)

delphi multithreading

7
推荐指数
1
解决办法
5940
查看次数

如何在扫描文件夹/子文件夹/文件时降低CPU使用率?

我开发了一个应用程序,它基本上扫描文件或文件列表的所有位置.当我扫描像10 000个文件和子文件这样的小文件夹时没有问题.但是当我扫描我的整个用户文件夹超过10万个项目时,我的处理器非常沉重.它占用了我处理器功耗的40%左右.

有没有办法优化此代码,以便它使用更少的CPU?

procedure GetAllSubFolders(sPath: String);
var
  Path: String;
  Rec: TSearchRec;
begin
  try
    Path := IncludeTrailingBackslash(sPath);
    if FindFirst(Path + '*.*', faAnyFile, Rec) = 0 then
      try
        repeat
          Application.ProcessMessages;
          if (Rec.Name <> '.') and (Rec.Name <> '..') then
          begin
            if (ExtractFileExt(Path + Rec.Name) <> '') And
              (ExtractFileExt(Path + Rec.Name).ToLower <> '.lnk') And
              (Directoryexists(Path + Rec.Name + '\') = False) then
            begin
              if (Pos(Path + Rec.Name, main.Memo1.Lines.Text) = 0) then
              begin
                main.ListBox1.Items.Add(Path + Rec.Name);
                main.Memo1.Lines.Add(Path + Rec.Name)
              end;
            end;

            GetAllSubFolders(Path + Rec.Name); …
Run Code Online (Sandbox Code Playgroud)

delphi

6
推荐指数
1
解决办法
556
查看次数

使用TRestRequest进行Delphi线程处理

我对RestRequest工具比较陌生.我希望有人解决了等待异步调用完成的问题......

我有一个程序,它生成数百个不同的api调用,然后调用处理结果,并将结果传递回调用api执行的过程,然后继续...

唯一的问题是总是做这样的电话,不必穿线,是软件挂起,直到通话结束...要尝试和解决这个问题,我改变RESTRequest.Execute;RESTRequest.ExecuteAsync();,但现在我的问题是,我的代码继续,而无需等待restrequest的响应.

再次试图绕过这个问题我尝试了几个解决方案,甚至api.RESTRequest.ExecuteAsync().WaitFor;(抛出错误thread error: the handler is invalid (6))

有没有什么方法我可以改变下面的函数作为一个单独的线程运行(只有执行部分在线程中运行很重要)...基本上我只想在每次调用函数时显示一个动画加载图标,并且对于我的其余代码来说,直到此功能完成...

我希望有一个更简单的解决方案,而不是开始使用多线程完全..

function run_api_command():boolean;
begin

  result := false;
  RESTResponse.Content.Empty;
  RESTAdapter.Dataset:= ds_action;
  RESTAdapter.RootElement:= '';

  try
    RESTRequest.ExecuteAsync;

    if(ds_action.Active = false) then ds_action.Active:=true;
    if(ds_action.FieldByName('result').AsString<>'Success') then
      begin
        showmessage(ds_action.FieldByName('result').AsString);
      end
    else
      begin
        RESTAdapter.RootElement:= 'data';
        result := true;
      end;
  except
    on E: Exception do
      begin
        if(e.Message = 'REST request failed: Error sending data: (12007) The server name or address could not be resolved') then
          begin
            if(messagedlg('Could not …
Run Code Online (Sandbox Code Playgroud)

delphi multithreading

6
推荐指数
2
解决办法
1299
查看次数

如何在delphi xe5 Firemonkey中使用android开发防止屏幕旋转

我发现以下代码可以防止屏幕旋转,但是当我编译时,我得到了一堆未声明的标识符:IFMXScreenService, TPlatformServices. 显然这是因为缺少单位。但是我找不到它是什么单位。

代码:

procedure TLogin.FormCreate(Sender: TObject);
var
  ScreenService: IFMXScreenService;
  OrientSet: TScreenOrientations;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService) then
  begin
    ScreenService := TPlatformServices.Current.GetPlatformService
      (IFMXScreenService) as IFMXScreenService;
    OrientSet := [TScreenOrientation.soLandscape];
    ScreenService.SetScreenOrientation(OrientSet);
  end;
end;
Run Code Online (Sandbox Code Playgroud)

任何帮助都会非常感谢。

更新:

缺少的单位是FMX.Platform。但是当我现在尝试编译时,出现错误:\\android\\debug\\libproject.so: open: permission denied

delphi android

3
推荐指数
2
解决办法
4939
查看次数

在模态对话框中使用TinyMCE

我试图用找到了jQuery的模态对话框类在http://www.jqueryscript.net/demo/jQuery-Modal-Dialog-Plugin-For-Bootstrap-3-Bootstrap-3-Dialog/examples/,至今它运行良好。

我唯一遇到的问题是TinyMCE,我想在表单中使用TinyMCE。而且我已经成功加载了TinyMCE实例,但是现在每当弹出tinymce中的另一个窗口时,例如图像或链接创建器窗口,我都无法在弹出表单中编辑文本框。

我检查了控制台日志,没有看到任何冲突或错误,有人可以解决可能的原因吗?

TinyMCE实例:

<script>
    tinymce.init({
            selector: 'textarea',
            relative_urls: false,
            remove_script_host: false,
            document_base_url: "https://mysite.co.za/",
            height: "360",
            fontsize_formats: "8pt 10pt 12pt 14pt 18pt 24pt 36pt",
            font_formats: "Andale Mono=andale mono,times;" +
                    "Arial=arial,helvetica,sans-serif;" +
                    "Arial Black=arial black,avant garde;" +
                    "Book Antiqua=book antiqua,palatino;" +
                    "Comic Sans MS=comic sans ms,sans-serif;" +
                    "Courier New=courier new,courier;" +
                    "Georgia=georgia,palatino;" +
                    "Helvetica=helvetica;" +
                    "Impact=impact,chicago;" +
                    "Symbol=symbol;" +
                    "Tahoma=tahoma,arial,helvetica,sans-serif;" +
                    "Terminal=terminal,monaco;" +
                    "Times New Roman=times new roman,times;" +
                    "Trebuchet MS=trebuchet ms,geneva;" +
                    "Verdana=verdana,geneva;" +
                    "Webdings=webdings;" +
                    "Wingdings=wingdings,zapf dingbats", …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery tinymce

1
推荐指数
1
解决办法
4074
查看次数

使用 Delphi 删除没有弹出窗口的文件

我正在使用以下代码删除文件夹的内容,我现在唯一的问题是,如果其中一个文件正在使用中,它会弹出一个确认对话框,然后开始向软件用户显示进度。

由于这些是临时文件,用户完全被弹出窗口弄糊涂了,并不断询问它。

有什么方法可以调整它,以便如果文件正在使用或无法删除,则代码将移至下一个文件并忽略此文件,直到下一次尝试。

代码

procedure DelFilesFromDir(Directory, FileMask: string; DelSubDirs: Boolean);
var
  SourceLst: string;
  FOS: TSHFileOpStruct;
begin
  FillChar(FOS, SizeOf(FOS), 0);
  FOS.Wnd := Application.MainForm.Handle;
  FOS.wFunc := FO_DELETE;
  SourceLst := Directory + '\' + FileMask + #0;
  FOS.pFrom := PChar(SourceLst);
  if not DelSubDirs then
    FOS.fFlags := FOS.fFlags OR FOF_FILESONLY;
  FOS.fFlags := FOS.fFlags OR FOF_NOCONFIRMATION;
  SHFileOperation(FOS);
end;
Run Code Online (Sandbox Code Playgroud)

delphi

1
推荐指数
1
解决办法
630
查看次数

标签 统计

delphi ×5

multithreading ×2

android ×1

html ×1

javascript ×1

jquery ×1

tinymce ×1