Недавно добавленные исходники

•  TDictionary Custom Sort  3 226

•  Fast Watermark Sources  2 992

•  3D Designer  4 751

•  Sik Screen Capture  3 259

•  Patch Maker  3 467

•  Айболит (remote control)  3 528

•  ListBox Drag & Drop  2 904

•  Доска для игры Реверси  80 790

•  Графические эффекты  3 843

•  Рисование по маске  3 172

•  Перетаскивание изображений  2 544

•  Canvas Drawing  2 672

•  Рисование Луны  2 500

•  Поворот изображения  2 093

•  Рисование стержней  2 120

•  Paint on Shape  1 525

•  Генератор кроссвордов  2 183

•  Головоломка Paletto  1 730

•  Теорема Монжа об окружностях  2 158

•  Пазл Numbrix  1 649

•  Заборы и коммивояжеры  2 017

•  Игра HIP  1 262

•  Игра Go (Го)  1 201

•  Симулятор лифта  1 422

•  Программа укладки плитки  1 177

•  Генератор лабиринта  1 512

•  Проверка числового ввода  1 297

•  HEX View  1 466

•  Физический маятник  1 322

•  Задача коммивояжера  1 357

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Использовать формы, объявленные в DLL



Оформил: DeeCo

{ 
  In the example that follows the exe only sees a totally "virtual 
  abstract" interface to the object as is being exported from the dll 
  but it still can create the object and use it. 
  Of course the exe can not see or execute any methods declared in the 
  exe but that is the whole purpose of implementing them in a custom dll 
  to begin with. 

  Im folgenden Beispiel sieht die Exe-Datei nur ein total "virtuelles, abstraktes" 
  Interface zum Objekt, welches aus der Dll importiert wird aber es 
  kann doch dieses Objekt erzeugen und es gebrauchen. 
}


 // Example code: 

program Dlloader;

 uses
   Sharemem,
   Forms,
   exeunit1 in 'exeunit1.pas' {Form1},
   DllIntfu in 'DllIntfu.pas';

 {$R *.RES}

 begin
   Application.Initialize;
   Application.CreateForm(TForm1, Form1);
   Application.Run;
 end.

 //-------------------------- 

unit DllIntfu;

 interface

 type
   TDllobject = class
   protected
     function Get_UserName: string; virtual; abstract;
     procedure Set_UserName(Value: string); virtual; abstract;
   public
     property UserName: string read Get_UserName write Set_UserName;
   end;
   TDllobjectClass = class of TDllobject;

 implementation

 end.

 //--------------------------- 

unit exeunit1;

 interface

 uses
   Windows, Messages, SysUtils, Classes, Graphics,
   Controls, Forms, Dialogs, DllIntfu, StdCtrls;

 type
   TForm1 = class(TForm)
     Button1: TButton;
     procedure Button1Click(Sender: TObject);
   private
     { Private declarations }
   public
     { Public declarations }
   end;

 var
   Form1: TForm1;

 implementation

 {$R *.DFM}

 type
   TDllfunc = function: TDllobjectClass;
    stdcall;

 procedure TForm1.Button1Click(Sender: TObject);
 var
   i: DWORD;
   fHandle: THandle;
   fDllfunc: TDllfunc;
   fDllobject: TDllobject;
   fUserName: string;
 begin
   fHandle := LoadLibrary('UserName.dll');
   if (fHandle <> 0) then
   begin @fDllfunc := GetProcAddress(fHandle, 'Dllfunc');
     if Assigned(@fDllfunc) then
     begin
       i := 255;
       SetLength(fUserName, i);
       GetUserName(PChar(fUserName), i);
       fUserName           := StrPas(PChar(fUserName));
       fDllobject          := fDllfunc.Create;
       fDllobject.UserName := fUserName;
       ShowMessage(fDllobject.UserName);
       fDllobject.Free;
     end;
     FreeLibrary(fHandle);
   end;
 end;

 end.

 //------------------------------- 

library UserName;

 uses
   Sharemem,
   Sysutils,
   DllIntfu;

 type
   TCustomDllobject = class(TDllobject)
   private
     fUserName: string;
     function Getfilecount: Integer;
   protected
     function Get_UserName: string; override;
     procedure Set_UserName(Value: string); override;
   end;

   TCustomDllobjectclass = class of TCustomDllobject;

 function TCustomDllobject.Getfilecount: Integer;
 var
   doserr: Integer;
   fsrch: TSearchRec;
 begin
   Result := 0;
   doserr := FindFirst('*.*', faanyfile, fsrch);
   if (doserr = 0) then
   begin
     while (doserr = 0) do
     begin
       if (fsrch.attr and faDirectory) = 0 then
         Inc(Result);
       doserr := findnext(fsrch);
     end;
     FindClose(fsrch);
   end;
 end;

 function TCustomDllobject.Get_UserName: string;
 begin
   Result := 'You signed on as ''' + fUserName + '''' +
     ' and there ' + IntToStr(Getfilecount) +
     ' files in this directory.';
 end;

 procedure TCustomDllobject.Set_UserName(Value: string);
 begin
   fUserName := Value;
 end;

 function Dllfunc: TCustomDllobjectClass; stdcall;
 begin
   Result := TCustomDllobject; // class type only 
end;

 exports
   Dllfunc name 'Dllfunc';

 begin
 end.




Похожие по теме исходники

DLL Form

DLL in Resources

DLL Injector




Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте