Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Forms

JoseCJoseC Member Posts: 17
I have two Forms that I want to send data between but all I get when I try is an EAccessViolation error, what's wrong?

This is a code snippet from my main form:
[code]
[b]uses[/b]
uReminder;

[b]procedure[/b] TfrmMain.FormCreate(Sender: TObject);
[b]begin[/b]
lblMoney.Caption := '0,0';
lblSecond.Caption := '00';
lblMinute.Caption := '00';
lblHour.Caption := '00';
[blue]frmReminder.txtNumber.Text := '';[/blue] [red]<-- Error line[/red]
[b]end[/b];
[/code]

Comments

  • zibadianzibadian Member Posts: 6,349
    : I have two Forms that I want to send data between but all I get when I try is an EAccessViolation error, what's wrong?
    :
    : This is a code snippet from my main form:
    : [code]
    : [b]uses[/b]
    : uReminder;
    :
    : [b]procedure[/b] TfrmMain.FormCreate(Sender: TObject);
    : [b]begin[/b]
    : lblMoney.Caption := '0,0';
    : lblSecond.Caption := '00';
    : lblMinute.Caption := '00';
    : lblHour.Caption := '00';
    : [blue]frmReminder.txtNumber.Text := '';[/blue] [red]<-- Error line[/red]
    : [b]end[/b];
    : [/code]
    :
    Your frmReminder form hasn't been created yet. Here is a summary of the creation order, which is basically every thing which happens before the mainform is shown:
    - Application.Initialize
    - Application.FormCreate(frmMain)
    - frmMain.OnCreate() called
    - Application.FormCreate(frmReminder (if second form))
    - frmReminder.OnCreate() called
    - Application.FormCreate(frmThirdForm)
    - frmThirdForm.OnCreate() called
    (Repeat for each auto-created form)

    Possible solutions:
    1 - Set the txtNumber.Text to empty using the Object Inspector and remove the blue line
    2 - Set the txtNumber.Text to empty in the frmReminder.OnCreate()
    3 - Remove the frmReminder from the Auto-create forms (Project Options Dialog - Forms Tag). Then create the frmReminder in the frmMain.OnCreate() like this:
    [code]
    frmReminder := TfrmReminder.Create(Application);
    [/code]
    After this you can place any assignment using the frmReminder or its components.
Sign In or Register to comment.