自定义 Form 设计中的参数传递问题

Hanklee 2000-04-25 11:41:00
各位:
我需要自定义一个 Form,完成一些信息输入的功能,并且把输入的内容传递到一个变量中。也就是说,有一个 Form,在调用时能向该 Form 中传递参数,在退出该 Form 能返回一个值。说白了,是类似于 VB 中的信息输入对话框。
由谁能告诉我该如何做?
...全文
149 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcw 2000-04-26
  • 打赏
  • 举报
回复
你在调用这个窗体的窗体上定义一个变量,然后在你调用这个窗体FREE之前
把你所输入的信息传入这个变量。
例:
var
meg:String;
begin
with TcallForm.create(self) do
try
if showmodal=mrok then
meg:=edit1.text;//(edit1.text为调用窗体输入信息)
finally
free;
end;
end;
sunsetyang 2000-04-25
  • 打赏
  • 举报
回复
创建一个窗体,显示时使用ShowModal(),退出后取成员变量的值,然后销毁。
光明山人 2000-04-25
  • 打赏
  • 举报
回复
Delphi4本来就有一个函数能实现这个功能:
function InputBox(const ACaption, APrompt, ADefault: string): string;
eaglet 2000-04-25
  • 打赏
  • 举报
回复
给你一个现成的 信息输入框的例子 ,你可以根据你的情况做
修改。函数 StrInputBox ;
function GetAveCharSize(Canvas: TCanvas): TPoint;
//得到字体在画布中的大小
function StrInputQuery(const ACaption, APrompt: string;
var Value: string ;MyFont : TFont): Boolean;
//动态生成FORM
function StrInputBox(const ACaption, APrompt, ADefault: string): string;
//信息输入框

function GetAveCharSize(Canvas: TCanvas): TPoint;
var
I: Integer;
Buffer: array[0..51] of Char;
begin
for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));
for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
Result.X := Result.X div 52;
end;

function StrInputQuery(const ACaption, APrompt: string;
var Value: string ;MyFont : TFont): Boolean;
var
Form: TForm;
Prompt: TLabel;
Edit: TEdit;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: Integer;
begin
Result := False;
Form := TForm.Create(Application);
with Form do
try
Canvas.Font := MyFont;
DialogUnits := GetAveCharSize(Canvas);
BorderStyle := bsDialog;
Caption := ACaption;

ClientWidth := MulDiv(180, DialogUnits.X, 4);
ClientHeight := MulDiv(63, DialogUnits.Y, 8);
Position := poScreenCenter;
Prompt := TLabel.Create(Form);
with Prompt do
begin
Parent := Form;
Prompt.Font := MyFont ;
AutoSize := True;
Left := MulDiv(8, DialogUnits.X, 4);
Top := MulDiv(8, DialogUnits.Y, 8);
Caption := APrompt;
end;
Edit := TEdit.Create(Form);
with Edit do
begin
Parent := Form;
Left := Prompt.Left;
Top := MulDiv(19, DialogUnits.Y, 8);
Width := MulDiv(164, DialogUnits.X, 4);
MaxLength := 255;
Text := Value;
SelectAll;
end;
ButtonTop := MulDiv(41, DialogUnits.Y, 8);
ButtonWidth := MulDiv(50, DialogUnits.X, 4);
ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent := Form;
Caption := '确定';
ModalResult := mrOk;
Default := True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent := Form;
Caption := '取消';
ModalResult := mrCancel;
Cancel := True;
SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth,
ButtonHeight);
end;
if ShowModal = mrOk then
begin
Value := Edit.Text;
Result := True;
end;
finally
Form.Free;
end;
end;



function StrInputBox(const ACaption, APrompt, ADefault: string): string;
var
MyFont : TFont ;
begin
Result := ADefault;
MyFont := TFont.Create ;
MyFont.Charset := GB2312_CHARSET ;
MyFont.Color := clWindowText ;
MyFont.Height := -16 ;
MyFont.Size := 9 ;
MyFont.Name := '宋体' ;
MyFont.Style := [] ;
StrInputQuery(ACaption, APrompt, Result,MyFont);
end;

5,402

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧