分类目录归档:Delphi

TIdFTP的DirectoryListing使用问题

IdFTP1.List;
ShowMessage(IntToStr(IdFTP1.ListResult.Count));
ShowMessage(IntToStr(IdFTP1.DirectoryListing.Count));

前者是正确的数值,后者是0。
看了一下网上的代码都是List完了就直接用,DirectoryListing会自动解析ListResult

放狗搜了半天,终于找到原因,原来是Indy10的一个设计上的变化,以下引用官网内容:

TIdFTP.DirectoryListing is returning nothing for my FTP server. Why?

We restructured the way FTP directory listing is done. The code is now a plug in system with various parsers in their own units which register themselves into a framework. To add support for a particular type of FTP server, you simply add the parser unit to one of your program unit’s uses clause.

To add the Unix directory list parser, add IdFTPListParseUnix to your unit’s clause. To add support for Microsoft Windows NT IIS FTP server, add IdFTPListParseWindowsNT to your uses clause. You can also add many other parsers we include in the Indy packages. By convention, they are named IdFTPListParser followed by the server type. You do not need to add IdFTPListParseBase to your uses clause because IdFTP uses that unit. If you wish to use all of Indy’s FTP List parser classes, just add the IdAllFTPListParsers unit to your uses clause.

We admit this new design is not as intuitive as the older one but this has many advantages for us such as:

• The FTP list parsing code is now much easier to maintain than the same code in a non-modular design in one unit which would be at least 150KB total.

• You now can add support for only the FTP servers you want your program support to support.

• You can now write your own custom parser classes and plug those into the standard FTP parsing list framework.

搜了一下IdFTPListParse有关的unit,有一大坨,要写个比较通用的FTP Client估计都得引进去吧……
idftplistparse.JPG

Windows API移动文件


function TScanFileThread.MoveFile(FileName: string): Boolean;
var
F: TShFileOpStruct;
begin
with F do begin
Wnd := Handle;
wFunc := FO_MOVE;
pFrom := PChar(Directory + FileName + #0#0);
pTo := PChar(SaveDirectory + FileName + #0#0);
fFlags := FOF_RENAMEONCOLLISION or FOF_NOCONFIRMMKDIR;
end;
if ShFileOperation(F) = 0 then begin
Result := True;
end
else begin
Result := False;
end;
end;

一开始pFrom和pTo没有以“#0#0”结尾,结果发现在有的机器上能移动成功,有的机器上SHFileOperation返回1026无法转移,查了一下资料

ShFileOperation中的pFrom和pTo中可以包含多个文件名,文件名之间用 ‘\0’ 分割,最后以两个\0结束。

TWebBrowser显示自定义Html内容


uses
ActiveX, MSHtml;

var
Document: IHtmlDocument2;
V: OleVariant;
begin
WebBrowser1.Navigate(‘about:blank’);
Document := WebBrowser1.Document as IHtmlDocument2;
V := VarArrayCreate([0, 0], varVariant);
V[0] := ‘Hello World’;
Document.Write(PSafeArray(TVarData(v).VArray));
end;

ASQLite3导致的日期问题

按照yyyy-m-d的方式插入时候,也就是个位数的月份不补零,插入正确,读取的时候直接报错或者直接是1899的默认日期了
按照yyyy-mm-dd的方式则插入读取都正常

因为用sqlite自己的命令行读取操作两种方式都没有问题,所以只能怀疑是ASQLite3封装的有问题了,lol

TTreeView的使用

先说一下我要达到的目的,一个Form分成两个Panel,左边放置TTreeView,右边根据TTreeView的不同选择切换不同的Frame或Form。

首先定义一个数据结构来保存每一个TTreeNode的数据,可以根据需要放更多的数据进去:

其中InstanceClass字段用来保存每个TTreeNode所对应的Frame或Form。

以如下定义为例:

开始创建TTreeView,在Form的OnCreate中创建:

响应TTreeView的OnChange事件,根据每个TTreeNode的Data定义显示不同的Frame或Form:

这样当需要添加新的Node时只需要更改很少的代码。

PS:相比于在Design视图上点来点去,还是更喜欢自己写代码来实现……