窗體建立和函式關聯相關的兩個小問題

2021-09-08 15:25:34 字數 1820 閱讀 9942

窗體建立和函式關聯相關的兩個小問題 vcl元件開發及應用

1,用窗體名稱作為傳入引數,建立窗體,怎麼避免重複建立?  

如下面**中注釋調的部分;使用not   assigned()判斷返回的結果每次都是false  

也就是說,assigned判斷結果一直為true。  

function   jaxcreateform(const   aformname:string):boolean;  

var  

aform:   tform;  

aformclass:   tformclass;  

begin  

try  

if   findclass(aformname)   <>   nil   then  

begin  

try  

aformclass   :=   tformclass(findclass(aformname));  

//             if   not   assigned(tform(copy(aformname,2,length(aformname)-1)))   then  

aform   :=   aformclass.create(nil);  

aform.show;             //mdi型別form不能使用showmodal釋放窗體;  

except  

aform.free;  

aform   :=   nil;  

end;  

end  

else   begin  

showmessage(format('建立窗體"%s"出錯!',[aformname]));  

end;  

except  

end;  

end;

2,動態建立的選單項,怎麼將其onclick事件與全域性tnotifyevent型別的函式關聯起來。  

with   tbutton.create(nil)   do  

begin  

parent   :=   self;  

caption   :=   '';  

onclick   :=   ?.  

end;

這個   視窗是不是自動建立的?

q:,動態建立的選單項,怎麼將其onclick事件與全域性tnotifyevent型別的函式關聯起來。  

with   tbutton.create(nil)   do  

----------------------------  

你的問題是選單項,   而你的**是tbutton。呵呵。   沒有關係,選單項也是一樣的

對不起,   剛才一直無法上來。  

procedure   buttononclick(sender:   tobject);  

begin  

showmessage('pointer,   pointer   ,   i   hate   you!');  

end;  

procedure   tform1.formcreate(sender:   tobject);  

begin  

with   tbutton.create(nil)   do  

begin  

parent   :=   self;  

visible   :=   true;  

@onclick   :=   @buttononclick;  

end;  

end;  

兩個窗體的值傳遞

目的 第乙個窗體 主窗體mainform 獲取第二個窗體 資料窗體dataform 的輸入值 方法一 推模式,主窗體公開方法!即把主窗體的例項推給資料窗體 步驟 1.主窗體新增公開方法 2.資料窗體新增帶引數的建構函式 3.資料窗體按鈕事件呼叫公開方法,傳遞使用者的輸入值 4.主窗體按鈕事件開啟資料...

union all關聯兩個不相關的表,按時間排序

表uc diary與uc photo是兩個完全不相關的表,用union all可以將這裡個表的資料關聯到一起,使用時間排序,常用於新鮮事的顯示,講日誌,相簿,說說等動態放到一起,安裝時間排序 select diary id as id,diary title astitle,diary text a...

C 兩個窗體間的通訊

c 實現在form1中呼叫form2的資訊的方式.方法1 首先,我們在form2中定義 private form1 mf form 其次,更改form2的建構函式為有引數的 public form2 form1 myform 最後,在form1中,在要用到form2的地方申明如下 form2 f2 ...