在Delphi中编程设计Form时,通常需要放置一些容器组件,如Panel,在其中放置别的组件。当一个组件被’Align To
Client’时,组件的父亲不容易用被选定以便修改属性。有一种特别简单的方法来选定组件的父亲。确保Form被激活,然后选择要找其父亲的组件,按[ESC]键,系统将自动选择组件的父亲,这个过程可以被重复,直至找到组件最终的父亲即Form,出现在对象浏览器中.
利用Windows 的全局原子表信息来实现此功能, Windows 的全局原子表可以被当前所有应用程序访问。它一共可包含37 项内容。
下面是实现代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
{搜寻表看是否程序已运行}
if GlobalFindAtom('PROGRAM_RUNNING') = 0 then
{ 如果没运行,则在表中增加信息 }
atom := GlobalAddAtom('PROGRAM_RUNNING')
else begin
{ 如果程序已运行,则显示信息然后退出 }
MessageDlg('You have the program running
all ready!!', mtWarning,[mbOK], 0);
Halt;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
{从表中移走信息以便程序能再运行}
GlobalDeleteAtom(atom);
end;
4、如何使你的窗口Stay on Top
begin
s:='';
theStringList:=TStringList.Create;
with tableName do
begin
try
Active:=True;
except
showmessage('Could not activate '+ Name);
end;
for j:=0 to (RecordCount-1) do
begin
s:='';
for i:=1 to (FieldCount-1) do
begin
(*add next field w/comma delimiter*)
s:=s+(Fields.AsString)+',';
end; (*i for*)
theStringList.add(s);
Next;
end; (*i for*)
theStringList.savetofile
(Name+'.csv'); (*memo1.lines.*)
Showmessage(Name+ ' has been backed up.');
close;
end; (*with*)
end; (*BackupTableToCSV*)
6、如何使用Show方法来显示一个模态窗口