Board index » delphi » HELP. "Compiler Error 48: Code Segment Too Large."

HELP. "Compiler Error 48: Code Segment Too Large."

One of my Units/Forms in Delphi 1.0  is too large ( > 65520 bytes) and
I have to break it into two or more units.

But how do I do that? As an example I have made a little code below and
want to make the "procedure TForm1.Button1Click(Sender: TObject);" in
Unit2 available to Unit1.

Any hints is greatly appreciated  :-)

Best regards,

Klaus Kristensen
Denmark in Europe
<kla...@login.dknet.dk>

{*********************************************************************}

unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

end.

{*********************************************************************}

unit Unit2

interface

implementation

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := 'Hello world';
end;

end.

{*********************************************************************}

 

Re:HELP. "Compiler Error 48: Code Segment Too Large."


Dans l'article <Q5iknisWnTf106...@login.dknet.dk>, kla...@login.dknet.dk
(Klaus Kristensen) crit :

Quote
>One of my Units/Forms in Delphi 1.0  is too large ( > 65520 bytes) and
>I have to break it into two or more units.
>But how do I do that? As an example I have made a little code below and
>want to make the "procedure TForm1.Button1Click(Sender: TObject);" in
>Unit2 available to Unit1.

Hmm...I advise you not to split events between units; I think it's a
one-way ticket to ProblemLand !
The best way to do it, IMHO, would be to put the code that is not strictly
related to the human interface in procedures, store them in another unit,
and call those procs from the first unit; that way, Delphi won't get
confused with his events.
That way, you'll also be able to change the interface without touching the
active code.

Happy pgming !
OMF

Re:HELP. "Compiler Error 48: Code Segment Too Large."


Klaus,

Quote
>But how do I do that? As an example I have made a little code below and
>want to make the "procedure TForm1.Button1Click(Sender: TObject);" in
>Unit2 available to Unit1.

I have worked around this problem by seperating out the processing that I
need in a stand-alone function.  For example, I need to calculate the
values entered by my user on a form I created.  Each line has a database
entry.  Therefore, on Form1 I place a TwwTable component and I pass it to
the function in UNIT2 when I call Calc100.

Main program somewhere down in UNIT1.PAS

   var
   Form1:  TForm1;

implementation
   uses Form2;

TForm1.Button1Click(Sender: TObject);
begin
   ...
   Total100Entries := Calc100(HUD1Table);
   ...

end;

In supporting module UNIT2.PAS...

var
   someGlobalvariable: string;

   function Calc100(HUD1Table:TwwTable): double;

{$R *.DFM}

implementation

function Calc100(HUD1Table:TwwTable): double;
begin
   with HUD1Table do begin
      Calc100 :=
      FieldByName('S101').AsFloat +
      FieldByName('S102').AsFloat +
      FieldByName('S104').AsFloat +
      FieldByName('S105').AsFloat;
   end;
end;

Now, I can have a button on Form1 or Form2 that is able to call the same
code to do some utility processing.  This often happens to me when I am
attempting to print sets of customized form.  The number of lines in a
code segment go beyond what Delphi 1.0 supports.  I don't know of a way
to have the method of one object call the method of another object in
another module.  Technically, it violates the seperation of concerns by
doing what you are suggesting.  I have had components share methods
within the same module.  I hope this helps.

William Olson

Re:HELP. "Compiler Error 48: Code Segment Too Large."


Quote
In article <Q5iknisWnTf106...@login.dknet.dk> kla...@login.dknet.dk (Klaus Kristensen) writes:
>One of my Units/Forms in Delphi 1.0  is too large ( > 65520 bytes) and
>I have to break it into two or more units.
>But how do I do that? As an example I have made a little code below and
>want to make the "procedure TForm1.Button1Click(Sender: TObject);" in
>Unit2 available to Unit1.
>Any hints is greatly appreciated  :-)

What you should do is to divide the program into code-segments ("units") which
contain a reasonable subset of the objects you need to refer to in your
program.

Every unit that needs to refer to one of those objects places the unit-name in
a "Uses" clause in the "Interface" part.  If you encounter "circular unit
references," move one or more unit-names to a "Uses" clause in the
"Implementation" part.

When one unit "uses" another, the unit can know everything about the "used"
unit that is in that unit's "interface" part -- this being the publicly
accessible face of the unit.  The "implementation" part is hidden.

If you find that you simply cannot create all of the code for an object in a
64K segment, you have to get a little creative -- defining procedures in
another unit and calling them from the first with "self" as a parameter.  But
that generally does not happen.

/mr/

Re:HELP. "Compiler Error 48: Code Segment Too Large."


Quote
Klaus Kristensen wrote:

> One of my Units/Forms in Delphi 1.0  is too large ( > 65520 bytes) and
> I have to break it into two or more units.

> But how do I do that? As an example I have made a little code below and
> want to make the "procedure TForm1.Button1Click(Sender: TObject);" in
> Unit2 available to Unit1.

> Any hints is greatly appreciated  :-)

> Best regards,

> Klaus Kristensen
> Denmark in Europe
> <kla...@login.dknet.dk>
> [ Example Deleted ]

Hi!

You shouldn't try and break up the methods into two units.  A method
only has access to private members if it is in the same unit.

A better approach is to examin your code and see if any lends itself to
being standalone classes, procedures and functions that can be used or
called from within your methods.  If you have exceeded the limit with
one form, this is probably the case.  

Then put those classes, functions and procedures into a separate unit.

Best Regards,

David S. Lee

Other Threads