We help IT Professionals succeed at work.

Delphi 7 SpeedButton causes crash

R_A_Martin
R_A_Martin asked
on
We have a system which has been using the same TSpeedButtons for the last 5 years.

In testing an update we find that opening and closing (TSpeedButton)  the program has a fatl crash, we have two error logging systems and neither of them catches the issue.

We have tracked it down to the use of TSpeedButton, all the code has been commented out and even just having fmForm.Close in the OnClick event the system still crashes.

Changing to a TBitBtn and we can go in and out of the form 100 times and still no crash.

Any suggestions as what the issue might be, the system has worked fine for a number of years.

We load programatically the glyph but again this code has been OK for a long time.

Comment
Watch Question

Commented:
a)   did you change the Windows version ?  

b) guess you are using already madshi (ww.madshi.org) ??

c)    can you provide a min.code fragment to test it here at EE  ??

Commented:
a)   did you change the Windows version ?  

b) guess you are using already madshi (ww.madshi.org) ??

c)    can you provide a min.code fragment to test it here at EE  ??

Have you tried enabling "Use Debug DCU's" in the project options and stepping through the code in the OnClick line by line?

Author

Commented:
BdLm

We have tested the software on XP, Vista and Win 7 and all give similar results.

We use XP as the development platform, although due to computer problems we did use a Win 7 machine until we got another XP machine, for the last few weeks we have been using XP.  So all the dll builds are XP.

Will try and get an example for you to test.

TheivingSix

We stripped everything out of the OnClick except fmForm.Close, so I do not think it anything in our exit code.
I understand that, I'm not saying it's you (But I can't rule it out). Debug DCU's are for stepping through all the Delphi components and units. Might be a bug in the VLC?

Commented:
btw :  

if you feel it is a delphi issue, have a look on the official delphi bug reports:


http://qc.embarcadero.com/wc/qcmain.aspx 


Author

Commented:
Not found anything there.

I thought I had found that the issue was my code, but a plain button with no code still gives an issue.

I am working new code at the moment using TBitBtn and it seems far more stable.

Can you give me any hints on using debug DCU's as I have tried to use them but none of my breaks stop the program execution.

It could be because I am working with DLL's, the main exe is from another vendor.

Author

Commented:
One more question if I may.

Where is the best place to programmatically set the properties of the buttons, FormCreate or FormActivate

Thanks
Regarding Debug DCUs

Breakpoint the "fmForm.Close" in the SpeedButton OnClick and press F7 until error. The line the error is on will help with finding your error.

Author

Commented:
I have tried this but the program does not break where I have marked it to, could this be because the code is in a dll.

Yes, yes it could. Maybe we could have a bit more context about how you're program works?

Author

Commented:
The program sits on a CAD engine and provides measurement routines for Quantity Surveyors who no CAD knowledge. We use Lisp in the CAD engine and Delphi dll's with functions in them.

There are two dll's each of which is over 5MB, could this be an issue, ie. too many functions in the dll, should I try to split them up.

We use a number of StringLists which are defined in a Unit where they were created, I am currently trying to move these to the main form of each function. Creating them in the OnCreate event and releasing them in the OnDestroy.

I am also commenting out code to see if I can find what is go on.

Eurekalog which normally catches memory leaks and AV's does not generate anything.

Commented:
did you exchange strings / stringslist over the dll ? and share between different code /LISP / delphi) ???  some dll  change in lisp???

what about a try with using fastmm4 for debugging ???  May be fastMM4 catches the AV .

Author

Commented:
I have now managed to get Eurekalog to give me the code where it goes wrong.

The error is


 2.4 Module Version:
  2.5 Type          : EPrivilege
  2.6 Message       : Privileged instruction.

This happens at the top of FormActivate and refes to the TAdvStringGrid we use


|Running Thread: ID=4528; Priority=0; Class=; [Main]                                 |
|------------------------------------------------------------------------------------|
|04F4AE30|QSCADSD.DLL|AsgUni.pas |                  |CreateUnicodeHandle    |1243[37]|
|04F4ACC4|QSCADSD.DLL|AsgUni.pas |                  |CreateUnicodeHandle    |1206[0] |
|04F4BF7C|QSCADSD.DLL|AsgUni.pas |TCustomUNIComboBox|CreateWindowHandle     |1937[1] |
|04F4BFA5|QSCADSD.DLL|AsgUni.pas |TCustomUNIComboBox|CreateWnd              |1942[1] |
|04F4A821|QSCADSD.DLL|AsgUni.pas |TComboBoxStrings  |Clear                  |1028[2] |
|05159CF0|QSCADSD.DLL|qscadSD.dpr|                  |dr_DrainageDetails_func|1351[38]|


I am going to try and comment out the ComboBox.Clear to see if this actually the reason.

|05159CF0|QSCADSD.DLL|qscadSD.dpr|                  |dr_DrainageDetails_func|1351[38]| this line number is not in the function which is being run but in the following one.



Author

Commented:
Further update.

It seems to be SmartInspect causing the issue, well I say that but it probably my implemention of it rather than the prodcuct.

I will do further testing tomorrow and post message.

If this is happening in OnFormClose set OnActivate := nil before you call the form close procedure.
Geert GOracle dba
Top Expert 2009
Commented:
you shouldn't set properties to initial values in formactivate

formactivate happens by example if open notepad, and then go back to your application
it gets called when windows has to "activate" your app again, because a other app was "active"

i allways use the overridden constructor of a object to set initial values

if you want TStrings descendant objects which only get instantiated the moment you use them, do something like this :

  private
    fList_A: TStrings;
  protected
    property List_A: TStrings read GetListA;
  public
    destructor Destroy; override;
  end;

function TAObject.GetListA: TStrings;
begin
  if not Assigned(fList_A) then
    fList_A := TStringList.Create;
  Result := fList_A;
end;

destructor TAObject.Destroy;
begin
  FreeAndNil(fList_A);
  inherited Destroy;
end;

use like this:
procedure TAObject.AProcedure;
begin
  List_A.Add('Item');
end;


Geert GOracle dba
Top Expert 2009

Commented:
the difference between a TBitBtn and a TSpeedButton is
TBitBtn is a control derived from TWinControl
and TSpeedButton from TGraphicControl

TSpeedbutton does not get focus when clicked

This may also cause problems (like when editing and the edit box expects to loose the focus)

Author

Commented:
We have removed the TSpeedbutton that was causing the problem, added a new one with the same name and re-linked its on click code and it works perfectly, anyone have any idea why this may have happened? Its as if the TSpeedbutton has been corrupted.
Geert GOracle dba
Top Expert 2009

Commented:
that can happen in the .dfm
manually editing is the most common cause

Author

Commented:
We seem to have the solution, by comparing new version with older code which worked it appears to be the way we were creating windows, we had changed (on advise from the CAD vendor) to use CreateParented, we chnaged back to using CreateForm and used the handle to SetParent value and so far seems to be OK.

Many thanks for all your help, I will split the points between everyone who responded

Author

Commented:
The solution was not what the original question asked about so cannot say Grade A but all the replys helped to nail it.