Delphi

Delphi stream panel to file

这一生的挚爱 提交于 2020-03-02 07:35:46
问题 today I've a question about streaming a part of a form to a file. In this example i use a Tmemo instead of file in order to see the stream. here is my form: The panel on the right top of the form has some controls, like label, edit and so on. with the "Save panel" butto I save the panel on a TStream: Here the code: procedure TfrmMain.btnSaveClick(Sender: TObject); var idx: Integer; MemStr: TStream; begin MemStr := TMemoryStream.Create; PanelStr := TMemoryStream.Create; try for idx := 0 to

Delphi & Datasnap - Connection Timeout, Communicataion Timeout or a way to avoid Client App to hang when no server response

放肆的年华 提交于 2020-03-02 05:44:34
问题 I am trying to use a Client-Server Datasnap based architecture. The client is inside an Android App that connects by Wifi with the Server Program which runs in a PC. This are the server and client features: Server Side: Server Methods TSQLConnection Driver: Firebird. KeepConnection: true. Server Container TDSServer Queuesize: 100 ChannelresponseTimeout: 3000 TDSTCPServerTransport BufferKBSize: 32 KeepAliveEnablement: kaDisabled MaxThreads: 30 PoolSize: 10 Port: 211 Client Side Main

Delphi & Datasnap - Connection Timeout, Communicataion Timeout or a way to avoid Client App to hang when no server response

泪湿孤枕 提交于 2020-03-02 05:44:27
问题 I am trying to use a Client-Server Datasnap based architecture. The client is inside an Android App that connects by Wifi with the Server Program which runs in a PC. This are the server and client features: Server Side: Server Methods TSQLConnection Driver: Firebird. KeepConnection: true. Server Container TDSServer Queuesize: 100 ChannelresponseTimeout: 3000 TDSTCPServerTransport BufferKBSize: 32 KeepAliveEnablement: kaDisabled MaxThreads: 30 PoolSize: 10 Port: 211 Client Side Main

Delphi - structures' strings not being freed [FastMM manager]

﹥>﹥吖頭↗ 提交于 2020-03-01 06:41:52
问题 If I declare PSomeStruct = ^TSomeStruct; TSomeStruct = record s1 : string; end; and I run the following code: var p: PSomeStruct; begin new(p); p^.s1:= 'something bla bla bla'; dispose(p); the FastMM 4 memory manager reports that there was a memory leak (type: string, data dump: "something bla bla bla"). However, if I do set the s1 string to empty before calling dispose it's OK. The second way I found is to change from record type to class, then instead of new I'm creating the instance, and

Delphi指针类型

不羁的心 提交于 2020-02-29 22:17:14
首先新建一个控制台项目:练习下指针类型的数据赋值和使用 program Project1; {$APPTYPE CONSOLE} uses SysUtils; type pint=^Integer;//定义指针类型 var a:Integer; b:Integer; c:Integer; pt:pint;//整形指针 p:Pointer;//无类型指针 begin a:=2; b:=3; pt:=@b;//整形指针指向整形数据 Writeln('pt=', pt^); p:=@a;//无类型指针指向整形数据 //Writeln('p=', p^);错误,无类型指针不能直接使用 Writeln('p=', Integer(p^)); //c:=p^;错误,无类型指针不能直接赋值给其他变量 c:=Integer(p^); Writeln('c=', c); pt:=p;//指针间赋值,可以不用类型转换 Writeln('pt=', pt^); Readln; end. 来源: https://www.cnblogs.com/qqook/p/3466872.html

Delphi中调用API函数经验点滴(三)

◇◆丶佛笑我妖孽 提交于 2020-02-29 10:02:40
三、防止多次载入应用程序实例   某些应用程序需要禁止用户载入多次实例。比如,控制面板中的应用程序,不管用户打开多少次,同一应用程序只有一个实例,而且每一次试图重复打开都会自动激活已经存在的实例。   Windows API 提供了函数FindWindow,可以是应用程序在启动时检查自己是否已经存在。   该函数在Delphi中的语法是:   function FindWindow(lpClassName: PChar, lpWindowName: PChar): HWND;   其中,参数lpCalssName 是要查找的窗口的类的名称,参数lpWindowName是要查找的窗口的标题(Caption)。 如果找到了相应的窗口实例,将返回一个非0 的该窗口句柄的整型值,否则返回0 。因此,只要判断应用程序的主窗口(或者伴随着应用程序存在而存在的窗口)是否存在就可以判断是否已经有实例存在了。   例如:   H := FindWindow('TForm1', nil);   if H = 0 then begin    ShowMessage('没有发现相同的应用程序实例。');    //加入加载应用程序的语句    //...   end else begin    ShowMessage('应用程序已经加载。');    SetActiveWindow(H);   end;

Delphi中调用API函数经验点滴

怎甘沉沦 提交于 2020-02-29 05:54:48
在Delphi中调用Windows API 函数十分方便,只需在单元的uses段加入Windows 单元名即可(对于由Delphi自动创建的单元,该项工作已经完成)。单元Windows.pas 已经由Delphi编写并直接提供开发者引用。笔者在开发Windows 应用时对于几个特别的API函数总结了一些经验供大家参考。以下开发经验均在Windows 9x中适用。 一、关闭系统   对于某些特殊的应用程序,可能需要进行关闭系统的操作,可以调用函数ExitWindows 或者ExitWindowsEx 来实现。   在Delphi中函数ExitWindows 的语法如下:   function ExitWindows(dwReserved: Cardinal; Code: Word): LongBool;   如果调用该函数成功,则返回True,否则返回False ;成功调用该函数将执行“关闭所有程序并以其他身份登录(Windows 95)”或“注销(Windows 98)”操作。其中的参数dwReserved和参数Code都必须是0 。   例如,要实现注销操作,只需要在适当的位置写入如下语句:   ExitWindows(0, 0);   执行关闭计算机或重新启动计算机的操作,可以通过调用函数ExitWindowsEx 来实现。   在Delphi中函数ExitWindowsEx

Delphi中调用API函数经验点滴(二)

给你一囗甜甜゛ 提交于 2020-02-29 05:54:39
二、弹出模式化对话框   在Delphi中,提供模式化对话框的方法很多,现对几种比较常用的方法做如下比较:   1) 直接调用Windows API 函数MessageBox   该方法一般情况下使用正常,而且根据不同的操作系统将显示相应的中文或英文按钮标题。而在笔者曾经开发的系统中,偶尔会出现该函数没有锁定 Handle所指的窗口的情况。通过观察发现,当入口参数的窗口句柄是Application.MainForm的窗口句柄时,没有出现类似情况。因此, 建议大家甚用。   2) 调用Delphi提供的函数MessageDlg   该方法的不足之处是,对话框的按钮标题是英文。   3) 调用Delphi提供的过程ShowMessage   该方法默认将应用程序的标题作为对话框的标题,并且仅仅是信息提示框,不太灵活。   4) 调用函数Application.MessageBox   该方法是笔者强力推荐使用的方法。该方法的使用效果与Windows API 函数MessageBox完全相同,并且不会出现有时没有锁定当前活动窗口的情况。   例如:   Aplication.MessageBox(Handle, '这是一条警告信息。', '警告', MB_OK + MB_ICONEXCLAMATION); 转自bbs.sendsms.cn 来源: oschina 链接: https:/

怎样在DELPHI中使用API函数

只谈情不闲聊 提交于 2020-02-29 05:26:21
实际上,在DELPHI中调用WIN32 API函数与在C或C++中调用WIN32 API函数没有大的区别。DELPHI中将C或C++中引用 的WINDOWS.H头文件改写为WINDOWS.PAS单元,使WINDOWS API函数的定义符合PASCAL语法。而其他的头文件在DELPHI中也都有相应的.PAS单元一一对应,所以在DELPHI中调用API函数时,只须 将相应的API函数单元加入到USES语句的单元之中,便可直接调用相应的函数了。   下面我们来看一个简单的例子,程序的作用是改变桌面墙纸:   unitUnit1;   interface   {Windows.PAS是DELPHI提供的标准单元,我们要调用API函数,需要引用这个单元}   usesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;   type     TForm1 =class(TForm);     Button1:TButton;     procedureButton1Click(Sender: TObject);     private{ Private declarations }     public {Public declarations }   end;   var

The difference between PopupMenuItem Click and MouseOver

跟風遠走 提交于 2020-02-28 07:52:07
问题 When a Menu Item has a sub Menu hovering the mouse expands the sub-menu it fires a click event. Is there any difference between this click event and if the user actually clicks? I'm using a TPopupMenu as dropdown property of a cxButton. EDIT Delphi 2007 回答1: Not sure this will work with D2007; it does in D7. Can you try the following? type THackPopupList = class(TPopupList) private FActuallyClicked: Boolean; protected procedure WndProc(var Message: TMessage); override; public property