Board index » delphi » Help. Error "Code segment too large"

Help. Error "Code segment too large"

Hello

At compiling the program Delphi gives the message : "Code segment too
large". I have tried to transfer a part of the program to a separate unit,
but it is necessary to send command from this module to a component of the
main window. Help me please, how can I compile the program ?

Thanks.

 

Re:Help. Error "Code segment too large"


Quote
In article <01bcb639$1ae779e0$1462e...@ced09.psru.ac.ru> "Puzanov Igor" <i...@pi.ccl.ru> writes:
>At compiling the program Delphi gives the message : "Code segment too
>large". I have tried to transfer a part of the program to a separate unit,
>but it is necessary to send command from this module to a component of the
>main window. Help me please, how can I compile the program ?

What you need to do is to place some of the code in a separate unit.  In the
"implementation" part of the form-unit, place a "uses" clause that refers to
the separate unit.  Then, in the "interface" part of the other unit, "use" the
form-unit.  (I may have that backward.)

In an appropriate place in the form-unit, call a routine in the other unit,
passing a copy of the calling form-instance if necessary.  If the unit needs
to send a command or call a method in the form it can do so, provided of
course that you are certain this cannot lead to endless recursion.

Re:Help. Error "Code segment too large"


Quote
> At compiling the program Delphi gives the message : "Code segment too
> large". I have tried to transfer a part of the program to a separate
unit,
> but it is necessary to send command from this module to a component of
the
> main window. Help me please, how can I compile the program ?

in the new unit make a reference to the main unit like this:

interface

uses
  main;

Then you can call the main window (called frmMain):

frmMain.component.property := value;

If it's a ListBox it could look like this:

frmMain.ListBox.Items.Clear;

--
Brian Pedersen, System Specialist, Alta Copenhagen
http://www.alta.dk
Personal homepage:
http://home6.inet.tele.dk/brianp

Get PR-Tracker -- tracks problem reports, defects, bugs
INFORMATION:  http://www.prtracker.com/info.html
DOWNLOAD:     http://www.prtracker.com/download.html

Re:Help. Error "Code segment too large"


The problem is that you did a source code too large and it exceeded 64k of
stack+heap. You must create a dll or remove (many) global variables(I
don't think that it solve your problem then make a dll!).
[]'s MDMSantos.

On 31 Aug 1997, Puzanov Igor wrote:

Re:Help. Error "Code segment too large"


In article <Pine.GSO.3.95.970909153725.15406B-100000@pesqueira> "Mrcio D. M. Santos" <m...@di.ufpe.br> writes:

Quote
>The problem is that you did a source code too large and it exceeded 64k of
>stack+heap. You must create a dll or remove (many) global variables(I
>don't think that it solve your problem then make a dll!).
>[]'s MDMSantos.

Actually, not quite, Marcio.

Yes, the DATA-segment in a Win31 program must contain the stack and the heap,
and the solution is generally to spin off the globals of the program into a
dynamically-created record (or object).  For example, I put the globals into
an object called "Global," in a unit called "Globals."  The main-program
creates this object on startup and destroys it at program shutdown.  A nice
side effect of this, of course, is that Delphi always sets new objects to
binary zeroes, so I don't have to initialize any globals if they're going to
be zero.

But the problem here is that the CODE segment is too large.  What this means
is that a single unit contains more than 64K of code.  And the solution is to
split the unit.  You create two units that "use" one another -- the uses
clauses are placed in the interface vs. the implementation part to avoid
"circular unit references."  Sometimes the solution in the case of a large
[VCL] object is to make the methods call a subroutine (in another unit)
passing "self" as a parameter.

It does not matter, actually, -where- the units are located.  They can be in a
DLL or they can simply be in the EXE itself.  The root cause of the problem is
that the x86 processor, operating in 16-bit mode, can never access more than
64K of "anything" using a single segment-register.  But when a call is made
from one unit to another, it is a "far" call which changes the value of the
code segment register as control passes from one segment to another.

/mr/

Other Threads