線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1236
推到 Plurk!
推到 Facebook!

錯誤訊息

答題得分者是:Justmade
nick899
一般會員


發表:16
回覆:22
積分:12
註冊:2002-12-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-26 23:43:09 IP:61.228.xxx.xxx 未訂閱
unit loginunit2;    interface    uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, Buttons, StdCtrls, ExtCtrls, janColorButton, SpotLabel, Label3D,   ButtonWithColor;    type   TMainForm2 = class(TForm)     HmbPanel1: TPanel;     HmbEdit1: TEdit;     HmbPanel2: TPanel;     HmbjButton6: TjanColorButton;     HmbjButton5: TjanColorButton;     HmbjButton1: TjanColorButton;     HmbjButton2: TjanColorButton;     HmbjButton3: TjanColorButton;     HmbjButton4: TjanColorButton;     HmbSpotLabel1: TSpotLabel;     HmbLabel3D1: TLabel3D;     HmbLabel1: TLabel;     HmbBitBtn1: TBitBtnWithColor;     HmbBitBtn2: TBitBtnWithColor;     procedure HmaBitBtn2Click(Sender: TObject);     procedure FormActivate(Sender: TObject);     procedure HmbBitBtn2Click(Sender: TObject);     procedure HmbBitBtn1MouseMove(Sender: TObject; Shift: TShiftState; X,       Y: Integer);     procedure HmbBitBtn2MouseMove(Sender: TObject; Shift: TShiftState; X,       Y: Integer);     procedure HmbPanel1MouseMove(Sender: TObject; Shift: TShiftState; X,       Y: Integer);     procedure HmbEdit1KeyDown(Sender: TObject; var Key: Word;       Shift: TShiftState);     procedure HmbjButton1click(Sender: TObject);   private     { Private declarations }   public     { Public declarations }   end;    var   MainForm2: TMainForm2;    implementation uses loginunit1,frm2comp;    {$R *.dfm}    // 開啟另一個form procedure OpenForm(FormClass: TFormClass; var fm; AOwner:TComponent); // 54 line   var:fm var  i:integer;  Child:TForm; begin   for i := 0 to Screen.FormCount -1 do     if Screen.Forms[i].ClassType = FormClass then begin         Child:=Screen.Forms[i];         if Child.WindowState=wsMinimized then            ShowWindow(Child.handle,SW_SHOWNORMAL)         else            ShowWindow(Child.handle,SW_SHOWNA);         if (not Child.Visible) then Child.Visible:=True;         Child.BringToFront;         Child.Setfocus;          TForm(fm):=Child;  // 68 line         exit;     end;   Child:=TForm(FormClass.NewInstance);   TForm(fm):=Child;   //  72 line   Child.Create(AOwner); end;    錯誤訊息 [Warning] loginunit2.pas(54): Unsafe type 'procedure, untyped pointer or untyped parameter' [Warning] loginunit2.pas(68): Unsafe typecast of 'procedure, untyped pointer or untyped parameter' to 'TForm' [Warning] loginunit2.pas(72): Unsafe typecast of 'procedure, untyped pointer or untyped parameter' to 'TForm'    procedure TMainForm2.HmbjButton1click(Sender: TObject); begin ///////   OpenForm(TMainForm21,MainForm21,self);  ////////// end;    end. 發表人 - nick899 於 2003/03/26 23:44:53 發表人 - nick899 於 2003/03/26 23:46:20
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-03-27 08:00:39 IP:218.16.xxx.xxx 未訂閱
是否應該這樣 : procedure OpenForm(FormClass: TFormClass; var fm : TForm; AOwner:TComponent);
nick167
中階會員


發表:86
回覆:133
積分:53
註冊:2003-02-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-03-27 08:18:57 IP:61.228.xxx.xxx 未訂閱
引言: var fm:Tform 測式後, OpenForm(TFormComp1,FormComp1,self);呼叫Form出現另一個error message 1. [Error] loginunit2.pas(83): Types of actual and formal var parameters must be identical 2. [Fatal Error] HCmychk.dpr(8): Could not compile used unit 'loginunit2.pas'
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-03-27 08:42:25 IP:218.16.xxx.xxx 未訂閱
那些 warning 有實則不良影響嗎? 若執行沒問題可不用理它們,因為你的程式事實上是有危險,fm 傳入甚麼也行,不一定是 TForm 的子代丫。    或,能否改成這樣(沒測試過) :
function OpenForm(FormClass: TFormClass; fm : TForm; AOwner:TComponent) : TForm;
var  i:integer;
 Child:TForm;
begin
  result := fm;
  for i := 0 to Screen.FormCount -1 do
    if Screen.Forms[i].ClassType = FormClass then begin
        Child:=Screen.Forms[i];
        if Child.WindowState=wsMinimized then
           ShowWindow(Child.handle,SW_SHOWNORMAL)
        else
           ShowWindow(Child.handle,SW_SHOWNA);
        if (not Child.Visible) then Child.Visible:=True;
        Child.BringToFront;
        Child.Setfocus; 
        exit;
    end;
  result:=TForm(FormClass.NewInstance);
  result.Create(AOwner);
end;
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-03-27 08:45:22 IP:218.16.xxx.xxx 未訂閱
補充呼叫時的改變
procedure TMainForm2.HmbjButton1click(Sender: TObject);
begin
///////
  MainForm21 := OpenForm(TMainForm21,MainForm21,self); 
//////////
end;
nick167
中階會員


發表:86
回覆:133
積分:53
註冊:2003-02-12

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-03-27 09:16:01 IP:61.228.xxx.xxx 未訂閱
引言: function OpenForm(FormClass: TFormClass; fm : TForm; AOwner:TComponent) : TForm; var i:integer; Child:TForm; begin result := fm; for i := 0 to Screen.FormCount -1 do if Screen.Forms[i].ClassType = FormClass then begin Child:=Screen.Forms[i]; if Child.WindowState=wsMinimized then ShowWindow(Child.handle,SW_SHOWNORMAL) else ShowWindow(Child.handle,SW_SHOWNA); if (not Child.Visible) then begin Child.Visible:=True; Child.BringToFront; Child.Setfocus; exit; end; // 是否要加begin ...end;,有或沒有是否有影響? end; result:=TForm(FormClass.NewInstance); result.Create(AOwner); end; [/code] mainform2 呼叫 FormComp1 FormComp1 := OpenForm(TFormComp1,FormComp1,self); error message: 1.[Error] loginunit2.pas(86): Incompatible types: 'TFormComp1' and 'TForm' 2. [Fatal Error] HCmychk.dpr(8): Could not compile used unit 'loginunit2.pas'
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-03-27 09:38:25 IP:218.16.xxx.xxx 未訂閱
FormComp1 := TFormComp1(OpenForm(TFormComp1,FormComp1,self)); 這樣就不會有 Compile Error ,不過你要試試能否逹到你要的效果。
nick167
中階會員


發表:86
回覆:133
積分:53
註冊:2003-02-12

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-03-27 13:54:44 IP:61.228.xxx.xxx 未訂閱
引言: 可以了,達到我所需要的,謝謝Justmade 但請原諒我又有一個小問題? mianform2.hide; // 先把 hide FormComp1 := TFormComp1(OpenForm(TFormComp1,FormComp1,self)); 當執行FormComp1之後在 onclose 加mainform2.show 每 *.exe 都有很都form,form1,form2,.....如何簡化form1.hide,在form2.onclose -> form1.show ......重覆寫程式... 可否請教Justmade 可有簡化方法,或它這麼做是必然的
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-03-27 14:31:03 IP:218.16.xxx.xxx 未訂閱
新問題請儘量開新題目。    在 TMainForm2 的 Public 加入 : procedure ChildFormClose(Sender: TObject; var Action: TCloseAction);    implementation : procedure TMainForm2.ChildFormClose(Sender: TObject; var Action: TCloseAction); begin   Show; close;    在 OpenForm 的最後加上 : result.OnClose := MainForm2.ChildFormClose;    若有些 Form 不是經由 OpenForm Create 的,那在 OpenForm 的 exit; 一包前也要加上 child.OnClose := MainForm2.ChildFormClose; 這樣就不用每個 Form 寫了 修正紅色部份。 發表人 - Justmade 於 2003/03/27 14:37:31
系統時間:2024-05-15 20:00:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!