Board index » delphi » really need a good idea

really need a good idea

we have 4 applications that are 10 megs apiece
each has a data-module which is same.
removing this data module from the application would make it only 5 megs.

is there anyway call the data module procedures at runtime and not have it
attached to the application?
ie -  like calling a DLL,,,,,,,,, i tried putting the data module inside of
a dll............ but when i call any procedure to manipulate the table or
tables, i get an EAccessViolation.

below is some experimental code that gives me the violation

unit RectangleMain;

interface

uses
  ShareMem,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, DBCtrls, Grids, DBGrids, DB, adsdata, adsfunc,
  adstable;

type
  TBoxProperties = procedure( L, H, W : Double; Var A, V : Double);
  TUpdateTable = procedure ( L, H, W, A, V : Double);

  TForm1 = class(TForm)
    tRectangle: TAdstable;
    dsRectangle: TDataSource;
    DBGrid1: TDBGrid;
    btnCalculate: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Le: TEdit;
    He: TEdit;
    Ve: TEdit;
    Ae: TEdit;
    We: TEdit;
    Button1: TButton;
    procedure btnCalculateClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    BoxProperties : TBoxProperties;
    UpdateTable : TUpdateTable ;
    RectangleLib : THandle;
    procedure pLoadRectangleDLL;
    procedure pFreeRectangleDLL;

    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
//**************************************************************************
****
procedure TForm1.pLoadRectangleDLL;
begin
  if RectangleLib = 0 then
  begin
    RectangleLib := LoadLibrary('RectangleLib.dll');
//    showmessage('loading dll');
    if RectangleLib = 0 then
      raise Exception.Create('Unable to load RectangleLib.dll')
    else
    begin
      @BoxProperties := GetProcAddress(RectangleLib, 'BoxProperties');
      @UpdateTable := GetProcAddress(RectangleLib, 'UpdateTable');
    end;
  end;
end;
//**************************************************************************
****
procedure TForm1.pFreeRectangleDLL;
begin
  if RectangleLib <> 0 then
  begin
    FreeLibrary(RectangleLib);
 //   showmessage('unloading dll');
    RectangleLib := 0;
  end;
end;
//**************************************************************************
****
procedure TForm1.btnCalculateClick(Sender: TObject);
var
  L, H, W, A, V : Double;
begin
  L := StrToFloat(Le.text);
  H:= StrToFloat(He.text);
  W:= StrToFloat(We.text);
  pLoadRectangleDLL;
  tRectangle.active := False;
  BoxProperties(L,H,W,A,V);
  Ae.text := FloatToStr(A);
  Ve.text := FloatToStr(V);
  tRectangle.active := True;
  pFreeRectangleDLL;
end;
//**************************************************************************
*************************
procedure TForm1.Button1Click(Sender: TObject);
var
  L, H, W, A, V : Double;
begin
  L := StrToFloat(Le.text);
  H := StrToFloat(He.text);
  W := StrToFloat(We.text);
  A := StrToFloat(Ae.text);
  V := StrToFloat(Ve.text);
  pLoadRectangleDLL;
   tRectangle.active := False;
  UpdateTable(L, H, W, A, V);   this is where i get the access violation
  tRectangle.active := True;
  pFreeRectangleDLL;
end;
end

here is the dll

library RectangleLib;

uses
  ShareMem,
  SysUtils,
  Classes,
  dataRectangle in 'dataRectangle.pas' {dmRectangle: TDataModule};

{$R *.res}

//**************************************************************************
****
function BoxArea( L, H, W : Double ) : Double;
begin
  Result := 2 * ( (L * H) + (L * W) + (H * W) );

end;
//**************************************************************************
****
function BoxVolume ( L, H, W : Double) : Double;
begin
  Result := L * H * W;
end;
//**************************************************************************
****
procedure BoxProperties( L, H, W : Double; Var A, V : Double);
begin
  A := BoxArea( L, H, W );
  V := BoxVolume ( L, H, W );
end;
//**************************************************************************
****
procedure UpdateTable( L, H, W, A, V : Double);
begin
with dmRectangle.tRectangle do
  begin
    active := True;
    edit;
    FieldByName('rLength').asFloat := L;
    FieldByName('rWidth').asFloat  := W;
    FieldByName('rHeight').asFloat := H;
    FieldByName('rArea').asFloat   := A;
    FieldByName('rVolume').asFloat := V;
    post;
    active := False;
  end;
end;

exports
  BoxProperties,
  UpdateTable;
begin
end.

 

Re:really need a good idea


Why not create an interface for the DataModule, which the datamodule
implements.  You can then place the datamodule into a package, and create
the datamodule after you load the package into memory.

Joe

Quote
"Mojoala" <j...@jimbishopcabinets.com> wrote in message

news:3cfd169c$1_2@dnews...
Quote
> we have 4 applications that are 10 megs apiece
> each has a data-module which is same.
> removing this data module from the application would make it only 5 megs.

> is there anyway call the data module procedures at runtime and not have it
> attached to the application?
> ie -  like calling a DLL,,,,,,,,, i tried putting the data module inside
of
> a dll............ but when i call any procedure to manipulate the table or
> tables, i get an EAccessViolation.

> below is some experimental code that gives me the violation

> unit RectangleMain;

> interface

> uses
>   ShareMem,
>   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
>   Dialogs, StdCtrls, Mask, DBCtrls, Grids, DBGrids, DB, adsdata, adsfunc,
>   adstable;

> type
>   TBoxProperties = procedure( L, H, W : Double; Var A, V : Double);
>   TUpdateTable = procedure ( L, H, W, A, V : Double);

>   TForm1 = class(TForm)
>     tRectangle: TAdstable;
>     dsRectangle: TDataSource;
>     DBGrid1: TDBGrid;
>     btnCalculate: TButton;
>     Label1: TLabel;
>     Label2: TLabel;
>     Label3: TLabel;
>     Label4: TLabel;
>     Label5: TLabel;
>     Le: TEdit;
>     He: TEdit;
>     Ve: TEdit;
>     Ae: TEdit;
>     We: TEdit;
>     Button1: TButton;
>     procedure btnCalculateClick(Sender: TObject);
>     procedure Button1Click(Sender: TObject);
>   private
>     BoxProperties : TBoxProperties;
>     UpdateTable : TUpdateTable ;
>     RectangleLib : THandle;
>     procedure pLoadRectangleDLL;
>     procedure pFreeRectangleDLL;

>     { Private declarations }
>   public
>     { Public declarations }
>   end;

> var
>   Form1: TForm1;

> implementation

> {$R *.dfm}

file://*********************************************************************
*****

- Show quoted text -

Quote
> ****
> procedure TForm1.pLoadRectangleDLL;
> begin
>   if RectangleLib = 0 then
>   begin
>     RectangleLib := LoadLibrary('RectangleLib.dll');
> //    showmessage('loading dll');
>     if RectangleLib = 0 then
>       raise Exception.Create('Unable to load RectangleLib.dll')
>     else
>     begin
>       @BoxProperties := GetProcAddress(RectangleLib, 'BoxProperties');
>       @UpdateTable := GetProcAddress(RectangleLib, 'UpdateTable');
>     end;
>   end;
> end;

file://*********************************************************************
*****
Quote
> ****
> procedure TForm1.pFreeRectangleDLL;
> begin
>   if RectangleLib <> 0 then
>   begin
>     FreeLibrary(RectangleLib);
>  //   showmessage('unloading dll');
>     RectangleLib := 0;
>   end;
> end;

file://*********************************************************************
*****

- Show quoted text -

Quote
> ****
> procedure TForm1.btnCalculateClick(Sender: TObject);
> var
>   L, H, W, A, V : Double;
> begin
>   L := StrToFloat(Le.text);
>   H:= StrToFloat(He.text);
>   W:= StrToFloat(We.text);
>   pLoadRectangleDLL;
>   tRectangle.active := False;
>   BoxProperties(L,H,W,A,V);
>   Ae.text := FloatToStr(A);
>   Ve.text := FloatToStr(V);
>   tRectangle.active := True;
>   pFreeRectangleDLL;
> end;

file://*********************************************************************
*****

- Show quoted text -

Quote
> *************************
> procedure TForm1.Button1Click(Sender: TObject);
> var
>   L, H, W, A, V : Double;
> begin
>   L := StrToFloat(Le.text);
>   H := StrToFloat(He.text);
>   W := StrToFloat(We.text);
>   A := StrToFloat(Ae.text);
>   V := StrToFloat(Ve.text);
>   pLoadRectangleDLL;
>    tRectangle.active := False;
>   UpdateTable(L, H, W, A, V);   this is where i get the access violation
>   tRectangle.active := True;
>   pFreeRectangleDLL;
> end;
> end

> here is the dll

> library RectangleLib;

> uses
>   ShareMem,
>   SysUtils,
>   Classes,
>   dataRectangle in 'dataRectangle.pas' {dmRectangle: TDataModule};

> {$R *.res}

file://*********************************************************************
*****
Quote
> ****
> function BoxArea( L, H, W : Double ) : Double;
> begin
>   Result := 2 * ( (L * H) + (L * W) + (H * W) );

> end;

file://*********************************************************************
*****
Quote
> ****
> function BoxVolume ( L, H, W : Double) : Double;
> begin
>   Result := L * H * W;
> end;

file://*********************************************************************
*****
Quote
> ****
> procedure BoxProperties( L, H, W : Double; Var A, V : Double);
> begin
>   A := BoxArea( L, H, W );
>   V := BoxVolume ( L, H, W );
> end;

file://*********************************************************************
*****

- Show quoted text -

Quote
> ****
> procedure UpdateTable( L, H, W, A, V : Double);
> begin
> with dmRectangle.tRectangle do
>   begin
>     active := True;
>     edit;
>     FieldByName('rLength').asFloat := L;
>     FieldByName('rWidth').asFloat  := W;
>     FieldByName('rHeight').asFloat := H;
>     FieldByName('rArea').asFloat   := A;
>     FieldByName('rVolume').asFloat := V;
>     post;
>     active := False;
>   end;
> end;

> exports
>   BoxProperties,
>   UpdateTable;
> begin
> end.

Other Threads