傳入類別的簡易問題 |
尚未結案
|
a6475
高階會員 發表:67 回覆:230 積分:154 註冊:2002-09-15 發送簡訊給我 |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TFormClass = class of TForm; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure ShowForm(AFormClass : TFormClass;var AForm ); end; var Form1: TForm1; Myform : TForm1; implementation {$R *.dfm} { TForm1 } type TFormClass = class of TForm; procedure TForm1.ShowForm(AFormClass: TFormClass; var AForm ); begin if TForm(AForm) = nil then TForm(AForm) := AFormClass.Create(Self); TForm(AForm).show; end; procedure TForm1.Button1Click(Sender: TObject); var t : PChar; begin ShowForm(TForm1,myForm); end;請問,當我把函數改成 procedure TForm1.ShowForm(AFormClass: TFormClass; var AForm : TForm); begin if AForm) = nil then AForm := AFormClass.Create(Self); AForm.show; end;為什麼麼就卡在ShowForm(TForm1,myForm);編譯不過呢? 如果我在把var 宣告拿掉,又可以,但是這樣如果連按兩次 就會有問題耶。 麻煩各位大大幫我解惑一下。 ..-----------βλμε------------.. ◎Oo月夜 光明 藍更愁oO◎ 藍調月光城v4:http://inping.myweb.hinet.net/ (暫時使用中..) 明日報(藍調.月光):http://mypaper2.ttimes.com.tw/user/a6475
------
月夜 光明 藍更愁 |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
|
James
高階會員 發表:10 回覆:290 積分:220 註冊:2002-07-25 發送簡訊給我 |
|
a6475
高階會員 發表:67 回覆:230 積分:154 註冊:2002-09-15 發送簡訊給我 |
感謝joe 和 James 大大的熱心分享。
原來用var型態要一樣。
不過James倒是用一行程式碼點醒夢中人~ 原來用轉型如可以了。謝謝大家。
順便分享一下,我現在的做法
procedure ShowForm(AFormClass : TFormClass;var AForm); begin //if not (TObject(AForm) is TForm) then exit; if TForm(AForm) = nil then TForm(AForm) := AFormClass.Create(fm_Main); TForm(AForm).show; end;..-----------βλμε------------.. ◎Oo月夜 光明 藍更愁oO◎ 藍調月光城v4:http://inping.myweb.hinet.net/ (暫時使用中..) 明日報(藍調.月光):http://mypaper2.ttimes.com.tw/user/a6475 發表人 - a6475 於 2004/12/29 09:24:16
------
月夜 光明 藍更愁 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |