小编Айм*_*мед的帖子

delphi文件搜索多线程

如果我执行它,我的应用程序将不会响应,直到找到所有文件和他们到列表框我的问题是如何我可以使这个功能多线程,以避免不相应的情况!我仍然是Delphi novoice

procedure TfrMain.FileSearch(const PathName, FileName : string; txtToSearch : string; const InDir : boolean);
var Rec  : TSearchRec;
    Path : string;
    txt  : string;
    fh   : TextFile;
    i    : integer;
begin


Path := IncludeTrailingBackslash(PathName);
if FindFirst(Path + FileName, faAnyFile - faDirectory, Rec) = 0 then
 try
   repeat

     AssignFile(fh, Path + Rec.Name);
     Reset(fh);
     Readln(fh,txt);

     if ContainsStr(txt, txtToSearch) then
        ListBox1.Items.Add(Path + Rec.Name);

   until FindNext(Rec) <> 0;
 finally
   FindClose(Rec);

 end;

If not InDir then Exit;

if FindFirst(Path + '*.*', faDirectory, Rec) = …
Run Code Online (Sandbox Code Playgroud)

delphi multithreading

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

检查ListBox中是否已选择某个项目

我想检查当用户点击标签时
是否在ListBox中选择了一个项目,如果我执行就像我得到了这个错误list index out of bounds

procedure TfrMain.Label15Click(Sender: TObject);
var
 saveDialog : TSaveDialog;
 FileContents: TStringStream;
 saveLine,Selected : String;
begin
 saveDialog := TSaveDialog.Create(self);
 saveDialog.Title := 'Save your text or word file';
 saveDialog.InitialDir := GetCurrentDir;
 saveDialog.Filter := 'text file|*.txt';
 saveDialog.DefaultExt := 'txt';
 saveDialog.FilterIndex := 1;

 Selected := ListBox1.Items.Strings[ListBox1.ItemIndex]; 

 if Selected <> '' then
 begin
  if saveDialog.Execute then
  begin
   FileContents := TStringStream.Create('', TEncoding.UTF8);
   FileContents.LoadFromFile(ListBox1.Items.Strings[ListBox1.ItemIndex]);
   FileContents.SaveToFile(saveDialog.Filename);
   ShowMessage('File : '+saveDialog.FileName)
  end
 else ShowMessage('Save file was not succesful');
  saveDialog.Free;
 end;
end;
Run Code Online (Sandbox Code Playgroud)

delphi listbox

5
推荐指数
1
解决办法
2万
查看次数

删除在运行时创建的TLabel

如何删除创建的标签,我google了很长时间但没有出现!,我尝试FindComponent但faild,我要做什么?我应该将父母设置为其他组件,如TPanel或什么?我感到很困惑!

procedure TForm1.Button1Click(Sender: TObject);
var
  lblLink: TLabel;
begin
   for i := 0 to stringtList.Count-1 do
   begin 
     lblLink := TLabel.create(self);

     with lblLink do
     begin
       name:='lblLink'+inttostr(i);
       caption:inttostr(i);
       Parent := self;
       font.style := [fsUnderline];
       cursor := crHandPoint;
       color := clBlue;
       font.Color := clBlue;
     end;
   end;
end;
Run Code Online (Sandbox Code Playgroud)

delphi vcl runtime

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

cast float to wchar_t win32

它吓坏了我,我无论如何都找不到把漂浮物扔给wchar_t,或者我看错了地方!

 float cNumbers[9]  = {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0};
 float x            = 3.0;
 float temp     = 0.0;
 wchar_t data[]     = {0};

 for(int i=0; i < sizeof(cNumbers); i++){

    temp = x / cNumbers[i];
    bool isInt = temp == static_cast<int>(temp);

    if(isInt){
        data =  temp; //this is a big fail
        addToList(hWnd,data);
    }
  }

void addToList(HWND hWnd,const wchar_t * data ){

  SendMessage(GetDlgItem(hWnd,IDC_LISTBOX),LB_ADDSTRING,0,(LPARAM)data); 
}
Run Code Online (Sandbox Code Playgroud)

问题是我想将浮点值转换为wchar_t以将其发送到列表框

c++ windows winapi visual-studio-2012

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

delphi TRegEx在perl样式正则表达式中不区分大小写的问题

我有一个问题,当我使用TRegEx对长文本和长文本来自网络!,我使用Indy获取网页源,然后我使用正则表达式找到链接!但正则表达式不能正常工作的问题!

我的正则表达式:

'/stream_map=(.[^&]*?)&/i'
Run Code Online (Sandbox Code Playgroud)

资源:

const HTTP_RESPONSE_OK = 200;

function GetPage(aURL: string): string;
var
  Response: TStringStream;
  HTTP: TIdHTTP;
begin
  Result := '';
  Response := TStringStream.Create('');
  try
    HTTP := TIdHTTP.Create(nil);
    try
      HTTP.Get(aURL, Response);
      if HTTP.ResponseCode = HTTP_RESPONSE_OK then begin
        Result := Response.DataString;
      end else begin
        // TODO -cLogging: add some logging
      end;
    finally
      HTTP.Free;
    end;
  finally
    Response.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
    var 
    regex : TRegEx;
    exper : string;
    result : string;
    fmatch : TMatchCollection;
    begin

    //Edit1.Text = http://www.youtube.com/watch?v=rzADrNmwYI0&feature=player_embedded 
    Memo1.Text := GetPage(Edit1.Text); …
Run Code Online (Sandbox Code Playgroud)

regex delphi

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

将字符串添加到列表框会产生奇怪的字符

我制作了一个使用 WIN32 将字符串发送到列表框的函数

char data[] = "abcd";

addToList(hWnd,data);

void addToList(HWND hWnd,char data[] ){
  SendMessage(GetDlgItem(hWnd,IDC_LISTBOX),LB_ADDSTRING,0,(LPARAM)data);    
}
Run Code Online (Sandbox Code Playgroud)

当我执行此操作时,它会将数据发送到列表框,但问题出现在奇怪的字符中,我也尝试过 wchar_t 但问题仍然存在

c++ windows winapi visual-studio-2012

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