Delphi-PRAXiS
Seite 3 von 4     123 4      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Komponente - Constructor MainForm.Hide = Access Violation??? (https://www.delphipraxis.net/104403-komponente-constructor-mainform-hide-%3D-access-violation.html)

p.abend 5. Dez 2007 13:46

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Jetzt habe ich doch noch eine Frage!

Wie kann ich denn jetzt von meinem RegForm aus auf die Variablen meiner Klasse zugreifen?

shmia 5. Dez 2007 16:09

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Zitat:

Zitat von p.abend
Wie kann ich denn jetzt von meinem RegForm aus auf die Variablen meiner Klasse zugreifen?

Das "tun man nicht", da es nicht objekt-orientiert ist.
Stattdessen bietet TRegForm ein oder mehrere Properties an:
Delphi-Quellcode:
else begin
   // RegForm anzeigen
   Application.ShowMainForm := false;
   RegForm := TRegform.create(nil);
   // Daten an Regform übergeben
   RegForm.ApplicationName := self.fApplicationName;
   if RegForm.showmodal = mrOK then
   begin
      // und auch entgegen nehmen
      self.regkey := RegForm.RegKey;
   end;
  end;

p.abend 5. Dez 2007 18:31

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Oh das wusste ich nicht! Danke für deine Hilfe.
Habe nur ein Problem, der kann mit der Zeile hier nichts anfangen...

Delphi-Quellcode:
..
RegForm.ApplicationName := self.fApplicationName;
..
Zitat:

[Pascal Fehler] RegUnit.pas(77): E2003 Undefinierter Bezeichner: 'ApplicationName'
Muss ich jetzt noch was beachten oder habe ich was falsch gemacht?

DeddyH 5. Dez 2007 18:36

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Hast Du denn eine Property ApplicationName im RegForm deklariert?

p.abend 5. Dez 2007 18:50

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Hatte ja am Anfang kurz geschrieben, dass das meine erste Kompo ist. Ich wusste nicht das ich noch eine property im RegForm anlegen muss.

Muss ich dann auch noch eine Property in meiner Klasse anlegen die ApplicationName heißt?

Ist das so für das Formular richtig?
Delphi-Quellcode:
  public
    { Public-Deklarationen }
    property ApplicationName: string;
  end;

DeddyH 5. Dez 2007 18:55

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Besser wäre
Delphi-Quellcode:
private
  FApplicationName: string;
public
  property ApplicationName: string read FApplicationName write FApplicationName;
end;
Und im Konstruktor FApplicationName gleich auf '' setzen.

p.abend 5. Dez 2007 19:05

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Also ich vermute mal das ich etwas falsch mache, denn der Wert wird nicht angezeigt.

mein RegForm
Delphi-Quellcode:
...
unit RegForm;

interface

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

type
  TRegForm = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Button2: TButton;
    Button3: TButton;
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
    FApplicationName: String;
  public
    { Public-Deklarationen }
    FRegCode: String;
    FRegWebsite: String;
    FRegExeName: String;
    FRegExtension: String;
    FRegFileName: String;
    FRegCustomerName: String;
    FRegCustomerEmail: String;
    FRegCustomerSerial: String;
    property ApplicationName: string read FApplicationName write FApplicationName;
  end;

var
  RegForm: TRegForm;

implementation

{$R *.dfm}

procedure TRegForm.Button2Click(Sender: TObject);
begin
 showmessage(fregcode);
end;

end.
...

Und in meiner Klasse steht jetzt
Delphi-Quellcode:
...
  strict private
    { Private-Deklarationen }
    ...
    FApplicationName: String;
  public
    { Public-Deklarationen }
    property ApplicationName : string read FApplicationName write FApplicationName;
...

DeddyH 5. Dez 2007 19:09

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Wo wird er nicht angezeigt?

p.abend 5. Dez 2007 19:16

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Im RegForm mit der Methode

Delphi-Quellcode:

procedure TRegForm.Button2Click(Sender: TObject);
begin
 showmessage(fregcode);
end;

DeddyH 6. Dez 2007 07:40

Re: Komponente - Constructor MainForm.Hide = Access Violatio
 
Du setzt eine Property ApplicationName und fragst dann eine Variable fRegCode ab? :gruebel:


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:31 Uhr.
Seite 3 von 4     123 4      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz