Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 May : access vilation when using dll

www.cryer.info
Managed Newsgroup Archive

access vilation when using dll

Subject:access vilation when using dll
Posted by:"landiin" (landi..@hotmail.com)
Date:6 May 2006 09:29:45 -0700

I'm having a bit of an issue. I'm new to programing so it something simple I'm sorry.

The dll file holds a TCustomFrom that is created at runtime.
When I call the dll it shows the window but gives me an access violation at address 0;

here is the code for the dll

library ExtLogWindow;

uses
  SysUtils,
  Classes,
  DWindow in '..\pass\DWindow.pas';

{$R *.res}
var
  ParseWindow: TParseWindow;

procedure CreateWindow(aOwner: TComponent; WindowCount: integer); stdcall;
begin
  ParseWindow := TParseWindow.CreateNew(AOwner);
  ParseWindow.WindowCount := WindowCount;
  ParseWindow.Show;
end;

Exports
  CreateWindow;

begin
end.

here is DWindow.pas

unit DWindow;

interface
uses Classes, Forms, Controls, StdCtrls, ComCtrls, ExtCtrls, Types;

type
  TParseWindow = Class(TCustomForm)
    private
      Button: TButton;
      StatusBar: TStatusBar;
      ComboBox: TComboBox;
      Memo: TRichEdit;
      Panel: TPanel;
      FWindowCount: Integer;
      procedure FOnPanelDraw(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);
    public
      constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override;
    published
      property WindowCount: integer read FWindowCount write FWindowCount;
end;

implementation

{ TParseWindow }


constructor TParseWindow.CreateNew(AOwner: TComponent; Dummy: Integer);
var
  p1,p2,p3: TStatusPanel;
begin
  inherited CreateNew(AOwner);
  Height  := 375;
  Width   := 475;
  StatusBar := TStatusBar.Create(Self);
  with Statusbar do
    begin
      Parent := Self;
      Height := 23;
      OnDrawPanel := FOnPanelDraw;
    end;
  p1 := StatusBar.Panels.Add;
  p1.Width := 150;
  p1.Style := psOwnerDraw;
  p2 := StatusBar.Panels.Add;
  p2.Width := 200;
  p2.Style := psOwnerDraw;
  p3 := StatusBar.Panels.Add;
  p3.Bevel := pbNone;
  Button := TButton.Create(StatusBar);
  with Button do
    begin
      Parent  := StatusBar;
      Caption := '&Start';
    end;
  ComboBox := TComboBox.Create(StatusBar);
  with ComboBox do
    begin
      Parent := StatusBar;
      items.Append('Combat: Hits You');
      items.Append('Combat: You Hit');
      items.Append('Combat: Heck If I Know');
      items.Append('It''s just in beta');
    end;
  Panel := TPanel.Create(Self);
  with Panel do
    begin
      Parent      := Self;
      Align       := alClient;
      BevelOuter  := bvNone;
      BevelInner  := bvLowered;
    end;
  Memo := TRichEdit.Create(Panel);
  with Memo do
    begin
      Parent    := Self;
      ReadOnly  := True;
      WordWrap  := False;
      Align     := alClient;
    end;
end;

procedure TParseWindow.FOnPanelDraw(StatusBar: TStatusBar;
  Panel: TStatusPanel; const Rect: TRect);
begin
  if Panel = StatusBar.Panels.Items[0] then
    begin
      button.Top    := Rect.Top;
      button.Left   := Rect.Left;
      button.Height := (Rect.Bottom - Rect.Top);
      button.Width  := (Rect.Right - Rect.Left);
    end
  else if Panel = StatusBar.Panels.Items[1] then
    begin
      ComboBox.Top    := Rect.Top;
      ComboBox.Left   := Rect.Left;
      ComboBox.Height := (Rect.Bottom - Rect.Top);
      ComboBox.Width  := (Rect.Right - Rect.Left);
    end;
end;

end.

finaly here is how I call the dll in the main form.

TParseWindow = procedure(AOwner: TComponent; WindowCount: integer);

...

procedure blah.buttonclick(Sender: TObject);
var
  iHandle: integer;
  LogWindow: TParseWindow;
begin
  iHandle := LoadLibrary('ExtLogWindow.dll');
  if iHandle <> 0 then
  begin
    @LogWindow := GetProcAddress(iHandle, 'CreateWindow');
    LogWindow(self, 0);
  end;
  FreeLibrary(iHandle);
end;

Glossary

File Types

Replies:

www.cryer.info
Managed Newsgroup Archive