Create table (code) in a dll

General TRichView support forum. Please post your questions here
Post Reply
haidomingo
Posts: 16
Joined: Tue Nov 10, 2009 7:27 pm

Create table (code) in a dll

Post by haidomingo »

I try to create a dll with inside this code:

Code: Select all

library lib01;

uses
  SysUtils, PngImage, RVtable, SclRView, RVStyle, Graphics;

{$R *.res}

procedure AdjustHeader(var TabHeader:TRVTableItemInfo);stdcall;
begin
    TabHeader.Cells[0,0].BestHeight := 1;
    TabHeader.Cells[0,0].BestWidth  := 1;
    TabHeader.Cells[0,1].BestHeight := 1;
end;

procedure MakeHeader(var RVStyleH:TRVStyle; var TabHeader:TRVTableItemInfo);stdcall;
var
  Pic  : TPngImage;
  r,c  : integer;

begin
  RVStyleH.TextStyles.Clear;
  with RVStyleH.TextStyles.Add do  begin
    FontName := 'Times New Roman';
    SizeDouble := 48;
    Color := clBlack;
    Style := [fsbold];
    StyleName:='T24'
  end;
  with RVStyleH.TextStyles.Add do  begin
    FontName := 'Times New Roman';
    SizeDouble := 24;
    Color := clBlack;
    Style := [];
    StyleName:='T12'
  end;
  with RVStyleH.TextStyles.Add do  begin
    FontName := 'Times New Roman';
    SizeDouble := 16;
    Color := clBlack;
    Style := [];
    StyleName:='T8'
  end;

  RVStyleH.ParaStyles.Clear;
  with RVStyleH.ParaStyles.Add do begin
    StyleName := 'Center';
    Alignment:=rvaCenter;
  end;

  TabHeader.CellHSpacing := 0;
  TabHeader.CellVSpacing := 0;
  TabHeader.Options := TabHeader.Options - [rvtoRowSizing, rvtoColSizing];

  TabHeader.BorderWidth := 0;
  TabHeader.CellBorderWidth := 0;

  for r := 0 to TabHeader.Rows.Count - 1 do
    for c := 0 to TabHeader.Rows[r].Count - 1 do
      TabHeader.Cells[r, c].Clear;

  TabHeader.Cells[0, 1].AddNL('Line1', 0, 0);
  TabHeader.Cells[0, 1].AddNL('Line2', 1, 0);
  TabHeader.Cells[0, 1].AddNL('Line3', 2, 0);

  Pic := TPngImage.Create;
  pic.LoadFromFile('logo.png');
  TabHeader.Cells[0,0].AddPictureEx('logo', pic, 0, rvvaMiddle);
end;

Exports
   MakeHeader,
   AdjustHeader;

begin

end.
Used with:

Code: Select all

var
  MakeHeader  : TMakeHeader;
  AdjustHeader : TAdjustHeader;
begin
  SRichViewEdit1.RichViewEdit.DocParameters.LeftMargin:=1.4;
  SRichViewEdit1.RichViewEdit.DocParameters.RightMargin:=1.4;
  SRichViewEdit1.RichViewEdit.DocParameters.TopMargin:=3.5;
  SRichViewEdit1.RichViewEdit.DocParameters.BottomMargin:=1.00;
  SRichViewEdit1.RichViewEdit.DocParameters.HeaderY:=0.8;
  SRichViewEdit1.RichViewEdit.DocParameters.FooterY:=0.6;

  dllHandle := LoadLibrary('lib01.dll') ;
  if dllHandle <> 0 then begin
      Tabellaheader := TRVTableItemInfo.CreateEx(1, 2,SRichViewEdit1.RVHeader.RVData);
      @MakeHeader  := GetProcAddress(dllHandle, 'MakeHeader') ;
      @AdjustHeader := GetProcAddress(dllHandle, 'AdjustHeader') ;

      if Assigned (MakeHeader) then
         MakeHeader(RVStyleH, TabellaHeader)
      else
         ShowMessage('"MakeHeader" not found') ;
      SRichViewEdit1.RVHeader.InsertItem('Header', TabellaHeader);
      if Assigned (AdjustHeader) then
         AdjustHeader(TabellaHeader)
      else
         ShowMessage('"AdjustHeader" notFound') ;
      FreeLibrary(dllhandle) ;
  end
  else begin
      ShowMessage('lib01.dll not found or ont load') ;
  end;
Unfortunately it does not work .. Access violation.
Thanks
Sergey Tkachenko
Site Admin
Posts: 17524
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Create table (code) in a dll

Post by Sergey Tkachenko »

I believe this code can work, but you need:
1) use run-time packages both in the main app and in dll
2) use common memory manager both in app and in dll: http://docwiki.embarcadero.com/RADStudi ... ing_Memory
Post Reply