Skip to main content
GameDev.net gamedev.net
🔒 Locked

inheritance in Delphi

Started by Radan Jan 26, 2003 at 3:58 PM 6 replies 350+ views
Original Post
Radan
Radan
Can anyone help me. I am trying to make my own form type. How do I make any form that derives from it behave the same. In particular, I want my application to have forms that glue to the edges of the screen, like WinAmp forms. The way I am trying to implement it is by having my own form type: TGlueForm = class(TForm) In TGlueForm I put all the code I need for "glueing" forms to edges of the screen and put it in its own unit. Then In my application I derive a form from it: TForm1:class(TGlueForm) but I have to make manual calls to inherited procedures to make it work. Can I make the form "Glue" just by deriving the form from TGlueForm and running the application?
-----------------Always look on the bright side of Life!
Ekas78
Ekas78
We need some source dude!
______Only dead fish go with the main-stream.
Maega
Maega
Yeah, that sounds about right.

TForm1 = class(TGlueForm)

Just make sure you include your unit.
Michalson
Michalson
In your project source (Project->View Source) what does the Application.CreateForm(..., ...) line look like? (or if you are creating the form dynamically somewhere else, post that code)
Radan
Radan
Ok this is the code to Form1, just any form but I derive it from TGlueForm(I am new here so I am not sure how that code thing works but I''ll try and guess):


unit TheGlueForm;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, GlueForm;

type
TForm1 = class(TGlueForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
//In order to make it work I need to use calls to inherited procedures
//with all the procedures:
procedure TForm1.FormCreate(Sender: TObject);
begin
inherited FormCreate(Sender);
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
inherited FormMouseMove(Sender,Shift,X,Y);
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited FormMouseDown(Sender,Button,Shift,X,Y);
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
inherited FormMouseUp(Sender,Button,Shift,X,Y);
end;

end.


type TGlue Form is declared in GlueForm unit, its just a normal form. Here is its interface, I''ll leave out the implementation, its just normal procedures that when executed glue the form to the edges of the screen(TA-DAM). Its interface:

unit GlueForm;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TGlueForm = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
dragging : boolean;
xs,ys : integer;
public
{ Public declarations }
end;


implementation
... etc., etc.


Oh yes:
Application.CreateForm(TForm1, Form1);


Any ideas how to get rid of all that inherited calls??
-----------------Always look on the bright side of Life!
daerid
daerid
[source][/source] tags please

[edited by - daerid on January 28, 2003 12:56:30 PM]
daerid@gmail.com
Radan
Radan
Sorry, I will use tags from now on.
-----------------Always look on the bright side of Life!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.