掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
フレームをDLLから追加するには? (ID:29413)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
いくつ増えるかわからない画面構成の違いを吸収するために、DLLに定義したフレームを読込んで、フォーム内に配置するサンプルプログラムを組んでいます。 フレームのParentプロパティをセットする時に「TFontをTFontに代入することはできません」というエラーが発生してしまいます。 何か解決方法は無いでしょうか? 環境はDelphi2007 for Win32 + WinXPです サンプル Unit1.pas type TControlClass = class of TControl; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private Handle : THandle; function CreateControl(ControlClass: TControlClass; const ControlName: string; X, Y, W, H: Integer): TControl; public end; var Form1: TForm1; implementation //uses Unit2; procedure TForm1.Button1Click(Sender: TObject); var LoadClass : TControlClass; MyFunc : function : TControlClass; stdcall; begin // LoadClass := TFrame2; // CreateControl(LoadClass, 'Frame1', 100, 100, 100, 10); if Handle <> 0 then begin @MyFunc := GetProcAddress(Handle, 'GetClass'); if @MyFunc <> nil then begin LoadClass := MyFunc; CreateControl(LoadClass, 'Frame1', 100, 100, 100, 10); end; end; end; function TForm1.CreateControl(ControlClass: TControlClass; const ControlName: string; X, Y, W, H: Integer): TControl; begin Result := ControlClass.Create(Form1); with Result do begin Parent := Form1 as TWinControl; Name := ControlName; SetBounds(X, Y, W, H); Visible := True; end; end; procedure TForm1.FormCreate(Sender: TObject); begin Handle := LoadLibrary('Project2.dll'); end; procedure TForm1.FormDestroy(Sender: TObject); begin if Handle <> 0 then FreeLibrary(Handle); end; end. Unit2.pas(Project2.dll側) type TControlClass = class of TControl; type TFrame2 = class(TFrame) private { Private declarations } public { Public declarations } end; implementation function GetClass : TControlClass; stdcall; begin Result := TFrame2; end; exports GetClass; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.