Solved

DLL's Froms

Posted on 2006-07-03
3
225 Views
Last Modified: 2010-04-05
Hi there!

I created exe file lets say its just myapp.exe. So in this app i have main form with 3 buttons thees buttons on click opens forms. So i like coding dll's in this way i write dll in begining like and then just convert my exe to dll in reality i just replace Application with word Library.

No prob take away some useles things like Application.run and so on. And you have ready dll wich will work.


But what i don't like. When i call a function from dll wich shows form its ok looks fine, but when i call forms from that main form in dll where i had thouse 3 buttons forms popsup like othere application ints not a application, but i can see it on startbar like application. Why it is so can it be made so it would not show the called form from dll like a app. For me its ok :) but if user will see it he won't understand it :)).

so here is a code peace wich i have in dll to call first form its main in dll and its shows it ok :)

library PK;

uses
  ShareMem, //yep :) i use it
  Forms,
  Classes,
  uMainP in 'uMainP.pas' {fProd_Kod},
  uKlases in 'uKlases.pas',
  uProdRekoridi in 'uProdRekoridi.pas',
  AdoToStream in 'AdoToStream.pas',
  uBin in 'uBin.pas' {fBin},
  uProdKriteriji in 'uProdKriteriji.pas' {fProdKriteriji},
  uRezultati in 'uRezultati.pas' {fRezultati},
  uJautajums1 in 'uJautajums1.pas' {fJautajums1},
  uJautajums2 in 'uJautajums2.pas' {fJautajums2},
  uJautajums3 in 'uJautajums3.pas' {fJautajums3},
  u_CardProd in 'u_CardProd.pas' {fCradProd};

{$R *.res}

procedure GoProdCode(_Sesija: pSession; Owner: TComponent); stdcall;
begin

  fProd_Kod := TfProd_Kod.Create(Owner);
  fBin := TfBin.Create(Owner);
  fProdKriteriji := TfProdKriteriji.Create(Owner);
  fRezultati := TfRezultati.Create(Owner);
  fJautajums1 := TfJautajums1.Create(Owner);
  fJautajums2 := TfJautajums2.Create(Owner);
  fJautajums3 := TfJautajums3.Create(Owner);
  fCradProd := TfCradProd.Create(Owner);

  Sesija := _Sesija;

  fProd_Kod.ShowModal;
end;
exports
  GoProdCode;

ok now i'm call GoProdCode from app to see the main form in dll.

i hope you understud what do i meen.

from  fProd_Kod form i will call othere forms wich are in dll and they will popup and will look like othere application they even don't have small icon in upper left corner.

thx,
kristao.

low exp in coding dll's using forms.
0
Comment
Question by:Kristao
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 125 total points
ID: 17033500
probably your Owner parameter is wrong... In most cases when we are using regular forms (not in DLL) the Owner is the Application
0
 
LVL 3

Expert Comment

by:jpedef
ID: 17035098
Hi!

First of all. Maybe you should use FastMM instead of Sharemem. You can get it free from Sourceforge http://fastmm.sourceforge.net

Then you should synchronize application and dll like:

// in dll
var
  dllApp: TApplication;
  fInitialized: boolean;

procedure InitLib(App: TApplication); stdcall;
begin
  // Synchronize application and dll
  if not fInitialized then
  begin
    dllApp := Application;
    Application := App;
    fInitialized := true;
  end;
end;

procedure DLLUnloadProc(Reason: Integer); register;  
begin                                                
  if Reason = DLL_PROCESS_DETACH then  
  begin
    // Dll is about to be unloaded
    Application := DllApp;
    fInitialized := false;
  end;
end;

//... other procedures

exports
  //... other procedures
  InitLib;

begin
  DLLProc := @DLLUnloadProc;
end.

InitLib should be called before any other proc in library.
0
 
LVL 1

Author Comment

by:Kristao
ID: 17035724
Hi there!

Answer is easy m'ky :)

I was on right way when i passed to dll TAplication. But it was't qwait right i needed to pass application.handle. So in reality its integer.

So what this how i did it.

I passed to dll integer wich is handle. and here is code peace:

from app

GoProdCode(ses; Application.Handle);

in dll

procedure GoProdCode(_Sesija: pSession; Owner: Integer); stdcall;
begin
  Application.Handle := Owner;

  Application.CreateForm(TfProd_Kod, fProd_Kod);
  Application.CreateForm(TfBin, fBin);
  Application.CreateForm(TfProdKriteriji, fProdKriteriji);
  Application.CreateForm(TfRezultati, fRezultati);
  Application.CreateForm(TfJautajums1, fJautajums1);
  Application.CreateForm(TfJautajums2, fJautajums2);
  Application.CreateForm(TfJautajums3, fJautajums3);
  Application.CreateForm(TfCradProd, fCradProd);

  Sesija := _Sesija;

  fProd_Kod.ShowModal; //palaižam moduli
end;
exports
  GoProdCode;

=) works fine.

thx.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month4 days, 18 hours left to enroll

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question