Author: Tomas Rutkauskas
TScreen, TApplication used in a DLL
Answer:
Each DLL in Delphi maintains its own instance of Application & Screen, your
DLL-calling application should send the its own Application and Screen values to
the DLL. The DLL should save and restore its original values.
You should put this code somewhere in your DLL and call the Init() function from
your application:
1 const2 SavedApplication: TApplication = nil;
3 SavedScreen: TScreen = nil;
4 5 // export this procedure and call it after loading the DLL6 7 procedure Init(anApplicationHandle, aScreenHandle: LongWord);
8 begin9 ifnot Assigned(SavedApplication) then10 begin11 SavedApplication := Application;
12 Application := TApplication(anApplicationHandle);
13 end;
14 15 ifnot Assigned(SavedScreen) then16 begin17 // ....same...18 end;
19 end;
20 21 initialization22 23 finalization24 if Assigned(SavedApplication) then25 begin26 Application := SavedApplication;
27 end;
28 29 if Assigned(SavedScreen) then30 begin31 // ....same.....32 end;
33 end.