delphi中想在按钮点击事件中,按一下按钮重新加载窗体一次。。
解决方案 »
- delphi处理tiff的问题.
- 不规则窗口的创建~
- 注册一个ocx的exe程序怎么写?
- DbGridEh的DbClick事件怎么不能得到选中的行数呢,请大侠指教
- 再问斑竹,信誉分是怎么计算的,为什么我的信誉分降的这么多
- ###########################dbgrid问题?##########################
- 急!!DBGrid中怎样控制在修改了某单元格中的值在失去焦点时写入数据库?
- 动态的生成 form
- 改用 ADO, 遇到 TBatchMove 的问题
- 窗体上的控件怎么存储???
- Dll窗体中的DBGridEh,如何解决用鼠标点击数据区无法获取焦点的问题
- linux编译报错?求大虾解释
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure ModifyObjectField(Obj: TObject; Offset: Integer; V: TObject);
begin
if(Assigned(Obj))then
try
PInteger(PAnsiChar(Obj) + Offset)^ := Integer(V);
except
end;
end;function GetErrorAddress(E: Exception; out Address: Cardinal): Boolean;
var
s : string;
p : PChar;
i : Integer;
begin
s := E.Message;
p := Pointer(s);
Result := False;
for i:=Length(s)-1 downto 0 do
begin
if(p[i]=' ')then
try
p[i] := '$';
Address := StrToInt(p+i);
Result := True;
Exit;
except
Result := False;
Exit;
end;
end;
end; function GetApplication_MainForm_Offset: Cardinal;
begin
try
Result := Cardinal(TApplication(nil).MainForm); { 只是为了引发一个异常,用来取得TApplication.FMainForm的相对地址 }
except
on E: Exception do
GetErrorAddress(E, Result);
end;
end; procedure CreateMainForm;
begin
Form1 := TForm1.Create(Application);
ModifyObjectField(Application, GetApplication_MainForm_Offset, Form1);
Form1.Show;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
CreateMainForm;
Free;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Caption := 'Old Form';
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
procedure ReloadForm;
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
ReloadForm;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Caption := 'Old Form';
end;procedure TForm1.ReloadForm;
var
i : Integer;
begin
Hide;
try
for i:=ComponentCount-1 downto 0 do
RemoveComponent(Components[i]);
InitInheritedComponent(Self, TForm);
finally
Show;
end;
end;end.