Form visible property causes wierd error..

I have coded my project several months now. And it works fine. Now it has started to give Access Violation error.
It creates Mainform and several other forms in startup. In mainform's on create event it should check and set other forms VISIBLE property. This worked fine, until now. I haven't changed the code, or done any other modifications. Now when i try to read or set forms visible property it gives an error: "Access Violation at address 004499DE in module "program name". Read of address FFFFFFFF."

When i click ok, the program will continue normally.

What causes this and how can i get rid of it ?

Help me !

It's wierd, because i havent changed those routines that affect or read the visible propertys, in several months..

DjDMacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nricoCommented:
The problem is: You are showin the other forms before they have been created, thus calling a method of a class that has not yet been instanced (right word?).

When you create those forms BEFORE your main form, the first you create will become your main form and will change it.

Solution:

Go to your project source, and cut the lines of

  Application.CreateForm()

EXCEPT your main form out of the project source, and past them AT THE BEGINNING of your MainForm.OnCreate, before the Form.Show() command.

This should do the trick.
0
DjDMacAuthor Commented:
No help! :(
Now i get even more Access violations..

And why the code worked earlier but now suddenly started to give these f***ing errors.. ?!?

0
florisbCommented:
Still no real help I think.....;-(

There's not really enough information to give a solution I think. Why not copy paste the exact code that gives the error, stripped from all other things. The error code you give doens't say much...

One thing, if your code worked Okee before, don't start changing things! The problem might be somewhere else (new Delphi version?, how are your directory settings? how do older versions work, you do have previous versions I hope?)

Or try to put the code in the OnShow / OnActivate event (please do add a global boolean to your project and use it so that your code will be called only once, if placed here).

I remember that using form.visible = true works different in newer versions...

Good Luck with  the |o|o| errors.

F-)




0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

DjDMacAuthor Commented:
I try couple of things first and if no help, then i post some source here.
I use Delphi 4 C/S.
Before i started to receive these errors, i changed the name of directory were projects is.. could this have anything to do with these errors ?
And what if those form files .DFM's are some way corrupted or something..

0
kretzschmarCommented:
hi djdmac,

didn't know why this happened, but maybe this workaroung helps

project source:

program app_;

uses
  Forms,
  app_u1 in 'app_u1.pas' {Form1},
  app_u2 in 'app_u2.pas' {Form2},
  app_u3 in 'app_u3.pas' {Form3};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.CreateForm(TForm3, Form3);
  Form1.StartUp(Application);  //look here
  Application.Run;
end.

mainform source :

unit app_u1;

interface

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

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    procedure StartUp(Sender: TObject);
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses app_u2, app_u3;

{$R *.DFM}

procedure TForm1.StartUp(Sender: TObject);
begin
  Form2.Visible := Not(Form2.Visible);  //or whatever
  Form3.Visible := Not(Form3.Visible);
end;

end.

well the forms are a bit empty in this sample :-)

meikl




0
florisbCommented:
Check project|options and there the directory's. Changing a directory name might result in Delphi searching (and finding!) parts of your application in the old directory!

Did you try to change it back, just to test?

I really don;t know about corrupted dfm's. Start with using view form (button in Delphi toolbar) to check whether Delphi can view all forms.

F.
0
MadshiCommented:
I think, nrico is right. Please post the project code here, and the MainForm.FromCreate code. Then we'll find the problem...

Regards, Madshi.
0
florisbCommented:
He! I posted an other comment, lost.

Please first check your directory settings, without changing anything the code did work before you changed the directory. The problem should be here...

F-)
0
rickpetCommented:
Delete or Rename all your *.dcu's I would  bet one is pointing to the wrong directory...

Rick
0
rarigoCommented:
Hi DjDMac,

   You can easily have wierds problems like these if you, like me, have a directory where you copy almost all components you think are good enough to keep a copy.
    If this is the case then rename this directory and create another with the old name and starting copying only those components your programs are asking for.
    if this is not the case then think of something like this. I bet it's the right direction.


sinceramente,
Reginaldo

0
wimmeyvaertCommented:
Yo DJDMAC,

Maybe you can check in the menu 'Project - Options - Forms'
Perhaps your forms are in the 'auto-create' list.

If you create your forms at runtime, then you'd better put them in the 'available forms' list.


Best regards,

The Mayor
0
DjDMacAuthor Commented:
[PROJECT SOURCE]

program WinDMP;

uses
  Forms,
  Main in 'Main.pas' {MainForm},
  TimeDate in 'TimeDate.pas' {TimeDateForm},
  About in 'About.pas' {AboutForm},
  PitchCalc in 'PitchCalc.pas' {PitchCalcForm},
  PlayList in 'PlayList.pas' {PlayListForm},
  PlayListAddDlg in 'PlayListAddDlg.pas' {PlayListAddDlgForm},
  NotePad in 'NotePad.pas' {NotePadForm},
  Chrono in 'Chrono.pas' {ChronoForm},
  ChroSet in 'ChroSet.pas' {ChronoSetF},
  Bpm in 'Bpm.pas' {BPMForm},
  BpmBrows in 'BpmBrows.pas' {BPMBrowserForm},
  Calculator in 'Calculator.pas' {CalculatorForm},
  DataBase in 'DataBase.pas' {DataBaseF},
  DBUpdate in 'DBUpdate.pas' {DatabaseUpdateForm},
  LookUpEdit in 'LookUpEdit.pas' {LookupEditForm},
  Details in 'Details.pas' {DetailsForm},
  Search in 'Search.pas' {SearchDialog};

{$R *.RES}

begin
  Application.Initialize;
  Application.Title := 'WinDMP [Special Edition]';
  Application.CreateForm(TMainForm, MainForm);
  Application.CreateForm(TBPMForm, BPMForm);
  Application.CreateForm(TTimeDateForm, TimeDateForm);
  Application.CreateForm(TAboutForm, AboutForm);
  Application.CreateForm(TPitchCalcForm, PitchCalcForm);
  Application.CreateForm(TPlayListForm, PlayListForm);
  Application.CreateForm(TPlayListAddDlgForm, PlayListAddDlgForm);
  Application.CreateForm(TNotePadForm, NotePadForm);
  Application.CreateForm(TChronoForm, ChronoForm);
  Application.CreateForm(TChronoSetF, ChronoSetF);
  Application.CreateForm(TBPMBrowserForm, BPMBrowserForm);
  Application.CreateForm(TCalculatorForm, CalculatorForm);
  Application.CreateForm(TDataBaseF, DataBaseF);
  Application.CreateForm(TDatabaseUpdateForm, DatabaseUpdateForm);
  Application.CreateForm(TLookupEditForm, LookupEditForm);
  Application.CreateForm(TDetailsForm, DetailsForm);
  Application.CreateForm(TSearchDialog, SearchDialog);
  Application.Run;
end.


[MAINFORM]

procedure TMainForm.FormCreate(Sender: TObject);
begin
       Set1Background:=ExtractFilePath(Application.ExeName)+'windmp.bmp';
       Set2Background:=ExtractFilePath(Application.ExeName)+'windmp.bmp';
       Set3Background:=ExtractFilePath(Application.ExeName)+'windmp.bmp';
       Set4Background:=ExtractFilePath(Application.ExeName)+'windmp.bmp';
       ActiveSET:=1;
       SaveAsDefault:=False;
       DetailsVisible:=False;
end;

procedure TMainForm.FormShow(Sender: TObject);
Begin
     DontSaveDefaultSet:=False;
     LMDTipDlg1.CaptionTitle:= '- XXXX '+Versio+' -';
     LMDTipDlg1.Execute;
     MainosBanneri.Lines[0]:='- XXXX '+ Versio+' - By Seppo ''DJ Lazy Jeff'' Sormunen';
     MainForm.Caption:='XXXX '+Versio;
     MainosBanneri.Scroll:=True;

<!1!> If FileExists(ExtractFilePath(Application.Exename)+'default.set') Then
  |    Begin
  |     LoadDefault:=True;
  |     M_LoadSetClick(self);
  |     LoadDefault:=False;
<!1!>  End;
end;

procedure TMainForm.M_LoadSetClick(Sender: TObject);
Var SF:TextFile;
    S:String;
begin

     SaveFormsToOldSet;
     LoadSetDialog.InitialDir:=ExtractFilePath(Application.Exename);

     If LoadDefault=True Then LoadSetDialog.Filename:='default.set';

     If LoadDefault=False Then
      If MessageDlg('Do you want to save your current desktops before loading a new ??',mtConfirmation, [mbYes, mbNo], 0) = mrYes then
       M_SaveSetClick(self);

     If LoadDefault=False Then LoadSetDialog.Execute;

      If LoadSetDialog.Filename<>'' Then
       Begin
        AssignFile(SF,LoadSetDialog.Filename);
        Reset(SF);
        ReadLn(SF,S);
        If S = '--- WINDMP SET FILE ---' Then // oikea file..
         Begin
          ReadLn(SF,S);
          If UpperCase(S)='TRUE' Then BPM_SetInfo[1]:=True Else BPM_SetInfo[1]:=False;
          ReadLn(SF,S);
          If UpperCase(S)='TRUE' Then BPM_SetInfo[2]:=True Else BPM_SetInfo[2]:=False;
          ReadLn(SF,S);
          If UpperCase(S)='TRUE' Then BPM_SetInfo[3]:=True Else BPM_SetInfo[3]:=False;
          ReadLn(SF,S);
          If UpperCase(S)='TRUE' Then BPM_SetInfo[4]:=True Else BPM_SetInfo[4]:=False;
          ReadLn(SF,S);
          BPM_Xpos[1]:=StrToInt(S);
          ReadLn(SF,S);
          BPM_Xpos[2]:=StrToInt(S);
          ReadLn(SF,S);
          BPM_Xpos[3]:=StrToInt(S);
          ReadLn(SF,S);
          BPM_Xpos[4]:=StrToInt(S);
          ReadLn(SF,S);
          BPM_Ypos[1]:=StrToInt(S);
          ReadLn(SF,S);
          BPM_Ypos[2]:=StrToInt(S);
          ReadLn(SF,S);
          BPM_Ypos[3]:=StrToInt(S);
          ReadLn(SF,S);
          BPM_Ypos[4]:=StrToInt(S);

      ReadLn(SF,S);
      DatabaseF.Grid.Columns[0].Width:=StrToInt(S);
      ReadLn(SF,S);
      DatabaseF.Grid.Columns[1].Width:=StrToInt(S);
      ReadLn(SF,S);
      DatabaseF.Grid.Columns[2].Width:=StrToInt(S);
      ReadLn(SF,S);
      DatabaseF.Grid.Columns[3].Width:=StrToInt(S);
      ReadLn(SF,S);
      DatabaseF.Grid.Columns[4].Width:=StrToInt(S);
      ReadLn(SF,S);
      DatabaseF.Grid.Columns[5].Width:=StrToInt(S);
      ReadLn(SF,S);
      DatabaseF.Grid.Columns[6].Width:=StrToInt(S);
      ReadLn(SF,S);
      DatabaseF.Grid.Columns[7].Width:=StrToInt(S);


          CloseFile(SF);
          FriendlyStatusBar1.Panels[2].Text:='Desktops loaded !';
         End;
       End;

       LoadCurrentSet;
end;

Procedure LoadCurrentSet;
Begin
     If BPM_SetInfo[ActiveSET]=True Then BpmForm.Show Else BpmForm.Close;
     If PITCH_SetInfo[ActiveSET]=True Then PitchCalcForm.Show Else PitchCalcForm.Close;
     If TIMEDATE_SetInfo[ActiveSET]=True Then TimeDateForm.Show Else TimeDateForm.Close;
     If CHRONO_SetInfo[ActiveSET]=True Then ChronoForm.Show Else ChronoForm.Close;
     If NOTEPAD_SetInfo[ActiveSET]=True Then NotePadForm.Show Else NotePadForm.Close;
     If PLAYLIST_SetInfo[ActiveSET]=True Then PlaylistForm.Show Else PlaylistForm.Close;
     If CALCULATOR_SetInfo[ActiveSET]=True Then CalculatorForm.Show Else CalculatorForm.Close;
     If BPMBROWSER_SetInfo[ActiveSET]=True Then BpmBrowserForm.Show Else BpmBrowserForm.Close;
     If DATABASE_SetInfo[ActiveSET]=True Then DataBaseF.Show Else DataBaseF.Close;
     If UPDATEDB_SetInfo[ActiveSET]=True Then DatabaseUpdateForm.Show Else DatabaseUpdateForm.Close;

       If BpmForm.Visible Then
        Begin
         BpmForm.Left:=BPM_Xpos[ActiveSET];
         BpmForm.Top:=BPM_Ypos[ActiveSET];
        End;

       If PitchCalcForm.Visible Then
        Begin
         PitchCalcForm.Left:=PITCH_Xpos[ActiveSET];
         PitchCalcForm.Top:=PITCH_Ypos[ActiveSET];
        End;

       If TimeDateForm.Visible Then
        Begin
         TimeDateForm.Left:=TIMEDATE_Xpos[ActiveSET];
         TimeDateForm.Top:=TIMEDATE_Ypos[ActiveSET];
         TimeDateForm.Height:=TIMEDATE_H[ActiveSET];
         TimeDateForm.Width:=TIMEDATE_W[ActiveSET];
         If TIMEDATE_Mode[ActiveSET]=1 Then
          Begin
           TimeDateForm.AnalogClock.Visible:=True;
           TimeDateForm.LCD_Time.Visible:=False;
           TimeDateForm.LCD_Date.Visible:=False;
          End
         Else
          Begin
           TimeDateForm.AnalogClock.Visible:=False;
           TimeDateForm.LCD_Time.Visible:=True;
           TimeDateForm.LCD_Date.Visible:=True;
          End;
        End;

       If ChronoForm.Visible Then
        Begin
         ChronoForm.Left:=CHRONO_Xpos[ActiveSET];
         ChronoForm.Top:=CHRONO_Ypos[ActiveSET];
        End;

       If NotePadForm.Visible Then
        Begin
         NotePadForm.Left:=NOTEPAD_Xpos[ActiveSET];
         NotePadForm.Top:=NOTEPAD_Ypos[ActiveSET];
         NotePadForm.Width:=NOTEPAD_W[ActiveSET];
         NotePadForm.Height:=NOTEPAD_H[ActiveSET];
        End;

       If PlayListForm.Visible Then
        Begin
         PlaylistForm.Left:=PLAYLIST_Xpos[ActiveSET];
         PlaylistForm.Top:=PLAYLIST_Ypos[ActiveSET];
        End;

       If CalculatorForm.Visible Then
        Begin
         CalculatorForm.Left:=CALCULATOR_Xpos[ActiveSET];
         CalculatorForm.Top:=CALCULATOR_Ypos[ActiveSET];
        End;

     If DataBaseF.Visible Then
        Begin
         DataBaseF.Left:=DATABASE_Xpos[ActiveSET];
         DataBaseF.Top:=DATABASE_Ypos[ActiveSET];
        End;

     If BpmBrowserForm.Visible Then
        Begin
         BpmBrowserForm.Left:=BPMBROWSER_Xpos[ActiveSET];
         BpmBrowserForm.Top:=BPMBROWSER_Ypos[ActiveSET];
         BpmBrowserForm.Height:=BPMBROWSER_H[ActiveSET];
        End;

     If DatabaseUpdateForm.Visible Then
        Begin
         DatabaseUpdateForm.Left:=UPDATEDB_Xpos[ActiveSET];
         DatabaseUpdateForm.Top:=UPDATEDB_Ypos[ActiveSET];
         DatabaseUpdateForm.Height:=UPDATEDB_H[ActiveSET];
        End;

End;

Procedure SaveFormsToOldSet;
Begin

<ERR>  If BpmForm.Visible Then BPM_SetInfo[ActiveSET]:=True Else BPM_SetInfo[ActiveSET]:=False;
     If PitchCalcForm.Visible Then PITCH_SetInfo[ActiveSET]:=True Else PITCH_SetInfo[ActiveSET]:=False;
     If TimeDateForm.Visible Then TIMEDATE_SetInfo[ActiveSET]:=True Else TIMEDATE_SetInfo[ActiveSET]:=False;
     If ChronoForm.Visible Then CHRONO_SetInfo[ActiveSET]:=True Else CHRONO_SetInfo[ActiveSET]:=False;
     If NotePadForm.Visible Then NOTEPAD_SetInfo[ActiveSET]:=True Else NOTEPAD_SetInfo[ActiveSET]:=False;
     If PlaylistForm.Visible Then PLAYLIST_SetInfo[ActiveSET]:=True Else PLAYLIST_SetInfo[ActiveSET]:=False;
     If DatabaseF.Visible Then DATABASE_SetInfo[ActiveSET]:=True Else DATABASE_SetInfo[ActiveSET]:=False;
     If BpmBrowserForm.Visible Then BPMBROWSER_SetInfo[ActiveSET]:=True Else BPMBROWSER_SetInfo[ActiveSET]:=False;
     If CalculatorForm.Visible Then CALCULATOR_SetInfo[ActiveSET]:=True Else CALCULATOR_SetInfo[ActiveSET]:=False;
     If DatabaseUpdateForm.Visible Then UPDATEDB_SetInfo[ActiveSET]:=True Else UPDATEDB_SetInfo[ActiveSET]:=False;


     If BpmForm.Visible Then
        Begin
         BPM_Xpos[ActiveSET]:=BpmForm.Left;
         BPM_Ypos[ActiveSET]:=BpmForm.Top;
        End;

     If PitchCalcForm.Visible Then
        Begin
         PITCH_Xpos[ActiveSET]:=PitchCalcForm.Left;
         PITCH_Ypos[ActiveSET]:=PitchCalcForm.Top;
        End;

     If TimeDateForm.Visible Then
        Begin
         TIMEDATE_Xpos[ActiveSET]:=TimeDateForm.Left;
         TIMEDATE_Ypos[ActiveSET]:=TimeDateForm.Top;
         TIMEDATE_W[ActiveSET]:=TimeDateForm.Width;
         TIMEDATE_H[ActiveSET]:=TimeDateForm.Height;
         If TimeDateForm.AnalogClock.Visible Then TIMEDATE_Mode[ActiveSET]:=1
        End;

     If ChronoForm.Visible Then
        Begin
         CHRONO_Xpos[ActiveSET]:=ChronoForm.Left;
         CHRONO_Ypos[ActiveSET]:=ChronoForm.Top;
        End;

     If NotePadForm.Visible Then
        Begin
         NOTEPAD_Xpos[ActiveSET]:=NotePadForm.Left;
         NOTEPAD_Ypos[ActiveSET]:=NotePadForm.Top;
         NOTEPAD_W[ActiveSET]:=NotePadForm.Width;
         NOTEPAD_H[ActiveSET]:=NotePadForm.Height;
        End;

     If PlayListForm.Visible Then
        Begin
         PLAYLIST_Xpos[ActiveSET]:=PlayListForm.Left;
         PLAYLIST_Ypos[ActiveSET]:=PlayListForm.Top;
        End;

     If CalculatorForm.Visible Then
        Begin
         CALCULATOR_Xpos[ActiveSET]:=CalculatorForm.Left;
         CALCULATOR_Ypos[ActiveSET]:=CalculatorForm.Top;
        End;

     If DataBaseF.Visible Then
        Begin
         DATABASE_Xpos[ActiveSET]:=DataBaseF.Left;
         DATABASE_Ypos[ActiveSET]:=DataBaseF.Top;
        End;


     If BpmBrowserForm.Visible Then
        Begin
         BPMBROWSER_Xpos[ActiveSET]:=BpmBrowserForm.Left;
         BPMBROWSER_Ypos[ActiveSET]:=BpmBrowserForm.Top;
         BPMBROWSER_H[ActiveSET]:=BpmBrowserForm.Height;
        End;

     If DatabaseUpdateForm.Visible Then
        Begin
         UPDATEDB_Xpos[ActiveSET]:=DatabaseUpdateForm.Left;
         UPDATEDB_Ypos[ActiveSET]:=DatabaseUpdateForm.Top;
         UPDATEDB_H[ActiveSET]:=DatabaseUpdateForm.Height;
        End;

End;


---------------------------------------------------------

When i remove the whole IF part marked with <!1!>, the program works.
But if i don't remove it the program will hang in line marked with <ERR>.

I tried to remove all .dcu's but it wont help.

I can get the program running now, by removing that default.set file's automatic
loading, but i really want to know whats wrong with the code..

I hope this code will show right..

Lazy Jeff

0
MadshiCommented:
It seems that the BpmForm is still not created, when your main form runs through FormShow. But in your project code you create that BpmForm before you call Application.Run, which shows your mainform.
So I see two possibilites, what's going wrong:
(1) One of the other forms call "MainForm.Show" or "MainForm.ShowModal" or "MainForm.Visible := true" in their FormCreate handler.
(2) One of the other forms call the "MainForm.FormShow(...)" or "MainForm.OnShow(...)" event directly.

Can this be? If not, you can send me the whole code to "madshi@gmx.net". Then I'll have a look at it. (I promise not to copy anything for my use... :-)

Regards, Madshi.

BPM_SetInfo is no dynamic array (something like "var BPM_SetInfo : type of OtherType;", is it?
0
MadshiCommented:
P.S: Please go with the Delphi debugger step by step through your project code (e.g. by pressing F8). After this line:

  Application.CreateForm(TBPMForm, BPMForm);

Is the "BPMForm <> nil"? If not: Here is the problem!!! If yes: Continue with the step by step debugging. You should reach Application.Run this way. If not: Tell us, which is the last line in your project, which you reach with F8? If yes: Continue debugging. Check "BPMForm" after each step. Is it still <> nil? Continue until you reach the <ERR> line. Someone must set it to nil!!! You have to find who does that.

Regards, Madshi.
0
MadshiCommented:
I've found the problem: In the object inspector set the "visible" property of your mainform to "false". It is "true" now and that produces all the problems.

Regards, Madshi.

P.S: Of course I deleted your sources again...  :-)  But I had no fun with them anyway, because I had to delete all components and most units in order to be able to compile the stuff.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DjDMacAuthor Commented:
Jiihaa !!
It worked !

But, why the mainforms visible can't be true ? What goes wrong when it's true ?

This is still a mystery to me, but
thanx for solving it !

Now i can get back to work.

Experts-Exchange really is the place to be when you have problems ! Great service !

Happy Lazy Jeff
0
MadshiCommented:
The problem is the following: Look at your project's sources. In the line

  Application.CreateForm(TMainForm, MainForm);

your mainform is being created. No problem so far. Normally the "visible" property is set to "false". So normally Delphi would jump to the FormCreate handler, then continue with the project's sources, that is creating the other forms. And normally your mainform's "visible" property would be set to "true" by the "Application.Run" call in your project.
But in your case Delphi shows the form already in the Application.CreateForm line. So Delphi jumps to the FormShow handler BEFORE the other forms are created. That's the problem...

Regards, Madshi.
0
DjDMacAuthor Commented:
Ahaa.. i see. Thank you for spending so much time to solve this problem, which seems to be my stupid mistake to turn visible property to true.. :)

0
MadshiCommented:
Well, the 500 points motivated me...   :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.