Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi 2006 build/compile problems 2

Status
Not open for further replies.

anderskyma

Programmer
May 4, 2010
3
NO
I've got a weird error in delphi 2006.

When doing a compile, my program works as it should.

When doing a build, the order of when forms are closed is changed(datamodule before form instead of the other way aronud), so when my Form1 tries to stop timers on my DataModule1, I get access violations.

When doing a compile again, everything works fine.

On other programs I have similiar problems with differences in compile/build.

I have tried this on 3 different computers, giving the same results.

In Projects->Options->Forms the forms are autocreated in this order:
Datamodule1
Form1


I have read about others having similiar problems here:

Does anyone know what is wrong with the delphi build? Does anyone know a solution to the problem?
 
the solution is simple.

let delphi autocreate only the main form.
create all other forms yourself.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Second what daddy said.

Additionally, I would put the creation of your datamodule in the OnCreate event of your main form. Don't forget to destroy it in the OnDestroy of your main form.

Roo
Delphi Rules!
 
Thanks :)

I've done what you suggested and it did not work. I guess it's a better way to create and destroy objects, so I'll keep the new setup.

I found a fix for my problem, but it's more like a hack. So I would love for some feedback.

Here's some declarations from my main form of the .exe

type
TErrVarName = array [C_ErrMinVarIndex..C_ErrMaxVarIndex] of ShortString;
var
UV_ErrVarName : TErrVarName;
UV_ErrVarValue: TErrVarName;


and in my code for the .exe file I had this which calls a function in a dll.:
ClearErrVarArrays(UV_ErrVarName, UV_ErrVarValue);


Here's the function declaration in my dll:

procedure ClearErrVarArrays(var whichErrVarName, whichErrVarValue : TErrVarName);
begin
//Fill empty string in the arrays for variables effected by Error.
FillChar(whichErrVarName, SizeOf(whichErrVarName), #0);
FillChar(whichErrVarValue, SizeOf(whichErrVarValue), #0);
end;


This happens if I do a build of the project
Before calling the dll function my datamodule is defined, but after returning from the dll function my datamodule has become 'nil'. Giving me an access violation when trying to access my datamodule.

If I do a compile the datamodule is declared for the whole process.


My hack was to move the code from the dll to the .exe. Duplicates code... :(
 
seems to mee you're doing something very wrong.
I have a hunch you are effectively overwriting the memory location where the pointer to the datamodule resides.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Yes, I agree, I must be doing something very wrong. I just can't see what it is. It seems like a wrong pointer is sent to the dll for some reason.

But I am really curious why a build gives a different result than a compile. The software has worked on delphi 5(and earlier versions) for more than 10 years, and it appeared in delphi2006.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top