小编Gle*_*rse的帖子

将文件名加载到TStrings中

您好我正在尝试将文件夹中的文件名列表加载到Stringlist中.我只想添加以.jpg结尾的文件名.当我现在运行它时,我得到访问冲突错误.这是我得到的.

选择目录.

procedure TMainForm.Load1Click(Sender: TObject);
var
  DirName: string;
begin
    mylist.Free;
    myList := TList<TBitmap>.Create;
  DirName := 'c:\';
  if SelectDirectory(DirName,[sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP)
  then;
    LoadImages(DirName);
end;
Run Code Online (Sandbox Code Playgroud)

获取文件夹中的totalfiles数

function GetFilesCount(Dir : string; Mask : string) : integer;
var
  Path : string;
begin
  Result := 0;
  for Path in TDirectory.GetFiles(Dir, Mask) do
    inc(Result);
end;
Run Code Online (Sandbox Code Playgroud)

从文件夹中获取文件名

function TMainForm.GetFilenames(Path: string ):TStrings;
var
  Dest: TStrings;
  SR: TSearchRec;
begin
  Dest.create;
  if FindFirst(Path+'*.*', faAnyFile, SR) = 0 then
  repeat
    Dest.Add(SR.Name);
  until FindNext(SR) <> 0;
  FindClose(SR);
  Result := Dest;
  Dest.Free;
end; …
Run Code Online (Sandbox Code Playgroud)

delphi

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

在TSTringlist中删除行

你好我正在写一些字符串列表的值.并希望从字符串列表中删除一个值.

目前我写这样的字符串列表.

   FGamePlay.Locations.strings[0] := ('NumberOfLocations='+inttostr(NOL+1));   //add one to total
   FGameplay.Locations.Add(inttostr(Position.x)+inttostr(Position.Y)+'=pos');  //add the location to list
Run Code Online (Sandbox Code Playgroud)

这将返回一个像这样的列表

INDEX    VALUE
[0]       NumberOfLocations=4
[1]       23=pos
[2]       34=pos
[3]       24=pos
[4]       52=pos
Run Code Online (Sandbox Code Playgroud)

现在我试着像这样删除它

FGamePlay.Locations.Delete(FGamePlay.Locations.IndexOf(inttostr(ePosition.x)+inttostr(ePosition.Y)));
Run Code Online (Sandbox Code Playgroud)

是ePosition.x + ePosition.Y将等于23,34,24或52.因此它应该删除该行,但是当我添加此删除行时,我得到索引超出范围-1.我确实在此行之前停止了代码并查看了Locations()并且其中包含了所有这些数字.还看了epostion和X,Y值是34,因此也是正确的.任何的想法?谢谢格伦

delphi

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

结果总是如此?

我试图返回一个函数的值来告诉我一个位置是否有该位置的熔岩或水.

问题是即使它有熔岩或水,它仍然会返回真实.水,熔岩和苍蝇的值来自玩家生物的列表.如果该生物具有水,熔岩或能够飞行的能力,那就是它.我只是将它们标记为真/假.位置是TPOINT.它将所有这些加载到一个函数中,只要函数CheckLocation返回true然后它的ok位置

  if FMyPlayers.Player[i].Values['water']='yes' then
       canwater := true;
   if FMyPlayers.Player[i].Values['Lava']='yes' then
       canlava := true;
   if FMyPlayers.Player[i].Values['fly']='yes' then
       canfly := true;
   cansnow := true;
   if checkLocation(position,cansnow,canlava,canwater,canfly) = False then
      exit;

function TBaseGameForm.checkLocation(position :Tpoint;Cansnow,canlava,canwater,canfly:bool):Bool;
begin
RESULT := True;
if canfly = true then
   RESULT := true
else begin
  if FGamePlay.waterLocations.IndexOfName('x'+inttostr(Position.x)+inttostr(Position.Y)) <> -1 then begin    //Check location
     Showmessage('Cant move there due to water');
     RESULT := FALSE;
   end;
  if FGamePlay.LavaLocations.IndexOfName('x'+inttostr(Position.x)+inttostr(Position.Y)) <> -1 then begin    //Check location
     Showmessage('Cant move there due to lava');
     RESULT := …
Run Code Online (Sandbox Code Playgroud)

delphi

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

使用AND和OR进行SQL查询

EDIT..sorry列是字符串db是mysql我相信.

我正在尝试进行查询,但不知道如何编写它,目前我有

   adoquery1.SQL.Add('SELECT * FROM workorder WHERE siteid=''p203'' AND worktype = ''CM'' AND reportdate > '''+edit1.text+'''') ;
Run Code Online (Sandbox Code Playgroud)

它使用日期分级器获取数据,然后使用edit1.text中的日期获取数据,我如何才能说出获取相同的数据但是在两个日期之间使用reportdate?

siteid = p203   AND
worktype = CM   AND
reportdate between edit1.text and edit2.text
Run Code Online (Sandbox Code Playgroud)

sql delphi

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

删除ansiString中的char

我有这个ansiString例如

DISC506002000001008100021041511207123051520515308154091550920TN177869-0151J1     36J207 70077       0                 0
Run Code Online (Sandbox Code Playgroud)

试图提取 TN177869-0151J1

但我正在使用的代码不断返回整个ansistring.

function TForm5.ParseDataPartNumber(Data: AnsiString):ansistring;
var
   ExtraData: Ansistring;
begin
    extraData := data;
    Delete(extraData,76,30);
    Delete(extraData,0,61);
    result:=extraData;
end;
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?是因为它是一个ansistring而不是字符串?那让我失望了?

delphi delphi-xe2

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

没有重载版本的写入

我正在与xe6中的代码共享一个项目,我正在使用xe2版本16.我收到此错误

There is no overloaded version of 'write' that can be called with these arguments

在这个代码.

  {$IF CompilerVersion >= 19}
  // Modified code for Delphi XE5 & later
  tcpConnection.IOHandler.Write(TheMsg, IndyTextEncoding.Default  );
  {$ELSE}
  // Original XE2 code
  tcpConnection.IOHandler.Write(TheMsg, TIdTextEncoding.Default);
  {$IFEND}
Run Code Online (Sandbox Code Playgroud)

我还添加idGlobal了用途.这会导致错误的任何其他原因?

delphi indy delphi-xe2 delphi-xe6

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

标签 统计

delphi ×6

delphi-xe2 ×2

delphi-xe6 ×1

indy ×1

sql ×1