![]() |
Re: Projekt "kopieren"
Ausgangspunkt :
Zitat:
Zitat:
Und wer sich die Mühe macht, das Beschriebene mal durchzuexerzieren, der soll sich mal die aus der Objektablage abgeleitete Form ansehen. Insbesondere auch die DFM. Jede Eigenschaft, die verändert wurde steht dann da drin als INHERITED. P.S.: Igotchas Bedenken wegen datensensitiver Komponenten kann ich nur bestätigen. |
Re: Projekt "kopieren"
Zitat:
:pale: :cry: Ich glaube bei mir fehlt einfach das Fundament.. Also, ich starte Delphi zum allerallerersten mal und weiss nicht, was man so damit machen muss :stupid: . Wo erstelle ich nun die Klasse TKontakt (bzw. bei mir TKundendaten)? Sage ich "Neue Anwendung" und schreibe den gesamten Code unter Unit1, oder sage ich "Neu/Unit", erstelle dort die Klasse und binde sie später zu meinem Projekt? Letzteres habe ich versucht und bei
Delphi-Quellcode:
ständig die Fehlermeldung
Kundendaten:= TKundendaten.Create;
Zitat:
Und bei
Delphi-Quellcode:
sagt der mir ständig
Kundendaten:= TKundendaten.Create(Self);
Zitat:
P.S.: Bitte nicht denken, dass ich hier nur auf Antworten warte. Ich schlage mich nebenbei durch Bücher und Tutorials durch, um die ganze Sache mit Klassen und Objekten zu verstehen. :) |
Re: Projekt "kopieren"
Zitat:
Und dann noch ein Vorschlag: Wenn du den Inhalt des neuen Threads vollständig in deinen Kopf injiziert hast :D reden wir über das Problem dieses Threads hier weiter. :) |
Re: Projekt "kopieren"
Hi,
wenn dieses Projekt kein reines Spaß und Lernprojekt ist, und es einfach darum geht aus drei Formularen sechs zu machen, und das Ding auch noch dieses Jahr fertig werden soll, (wegen des bei dir ansonsten noch nötigen know how Aufbbaus), und du das beruflich brauchst, würde ich einfach folgendes Copy Paste Vorgehen empfehlen: Einfach Formular in der IDE aktivieren, "speichern unter" anwählen, das alte Formular wieder dem Projekt hinzufügen, und das für alle drei Formulare und dann halt die neuen Anpassen. Oder einfach (s. Hansa) Formulare der Objektverwaltung hinzufügen, und von da wieder dem Projekt hinzufügen. Und dann die Änderungen anbringen. Auch in diesem Fall würde ich aber kopieren, und für dich noch nicht vererben empfehlen. Während du das tust, kannst du ja so nebenbei mal schauen, wie Objektorientierung und Vererbung es dir ermöglichen, Dinge die in beiden Funktionalitäten identisch sind, nur einmal zu coden. Woki |
Re: Projekt "kopieren"
Zitat:
Delphi-Quellcode:
Hierbei sind alle "property"-Methoden mal weggelassen worden (durch SHIFT+STRG+C werden diese automatisch erstellt.
unit UContact;
interface uses Contnrs, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset, xMain, Dialogs, UCustomer; type TContactCustomerAdds = class(TObject) private FCustomerID: integer; FPhone1: String; FPhone2: String; FMobile: String; FFax: String; FEmail: String; FAssName: String; FAssPhone: String; FAssEmail: String; procedure SetFCustomerID(const Value: integer); procedure SetFPhone1(const Value: String); procedure SetFAssEmail(const Value: string); procedure SetFAssName(const Value: string); procedure setFAssPhone(const Value: string); procedure SetFEmail(const Value: string); procedure SetFFax(const Value: string); procedure SetFMobile(const Value: string); public property CustomerID: integer read FCustomerID write SetFCustomerID; property Phone1: String read FPhone1 write SetFPhone1; property Phone2: String read FPhone2 write SetFPhone1; property Mobile: string read FMobile write SetFMobile; property Fax: string read FFax write SetFFax; property Email: string read FEmail write SetFEmail; property AssName: string read FAssName write SetFAssName; property AssPhone: string read FAssPhone write setFAssPhone; property AssEmail: string read FAssEmail write SetFAssEmail; constructor create; end; type TContact = class(TObject) private FContactID: integer; FSalutation: integer; FTitle: integer; FFName1: String; FFName2: String; FLName: String; FBirthdate: TDateTime; FPAddStreet: String; FPAddPostal: String; FPAddCity: String; FPAddRegion: String; FPAddCountry: Integer; FPhone1: String; FPhone2: String; FMobile: String; FFax: String; FEMail1: String; FEmail2: String; FContactBy: Integer; FContactDate: TDateTime; FContactCreatedBy: Integer; FMaritalStatus: Integer; FMALetter: integer; FMAEmail: integer; FMAFax: integer; FMAPhone: integer; FNote: String; FAddNote: String; FCustomerList: TObjectList; FCustomerAddsList: TObjectList; OQuery1, OQuery2: TZQuery; procedure SetFCcontactID(const Value: Integer); procedure SetFFName1(const Value: String); procedure SetFSalutation(const Value: Integer); procedure SetFTitle(const Value: Integer); procedure SetFBirthdate(const Value: TDateTime); procedure SetFFName2(const Value: String); procedure SetFLName(const Value: String); procedure SetFPAddStreet(const Value: String); procedure SetFPAddCity(const Value: String); procedure SetFPAddPostal(const Value: String); procedure SetFPAddRegion(const Value: String); procedure SetFPhone1(const Value: String); procedure SetFEMail1(const Value: String); procedure SetFFax(const Value: String); procedure SetFMobile(const Value: String); procedure SetFPhone2(const Value: String); procedure SetFEMail2(const Value: String); procedure SetFPAddCountry(const Value: Integer); procedure SetFContactBy(const Value: Integer); procedure SetFContactDate(const Value: TDateTime); procedure SetFContactCreatedBy(const Value: Integer); procedure SetFMaritalStatus(const Value: Integer); procedure SetFMALetter(const Value: integer); procedure SetFMAEmail(const Value: integer); procedure SetFMAFax(const Value: integer); procedure SetMAPhone(const Value: integer); procedure SetFNote(const Value: String); procedure SetFAddNote(const Value: String); procedure SetFCustomerList(const Value: TObjectList); procedure SetFCustomerAddsList(const Value: TObjectList); public property ContactID: Integer read FContactID write SetFCcontactID; property Salutation: Integer read FSalutation write SetFSalutation; property Title: Integer read FTitle write SetFTitle; property ForeName1: String read FFName1 write SetFFName1; property ForeName2: String read FFName2 write SetFFName2; property LastName: String read FLName write SetFLName; property Birthdate: TDateTime read FBirthdate write SetFBirthdate; property Street: String read FPAddStreet write SetFPAddStreet; property Postal: String read FPAddPostal write SetFPAddPostal; property City: String read FPAddCity write SetFPAddCity; property Region: String read FPAddRegion write SetFPAddRegion; property Country: Integer read FPAddCountry write SetFPAddCountry; property AddNote: String read FAddNote write SetFAddNote; property Phone1: String read FPhone1 write SetFPhone1; property Phone2: String read FPhone2 write SetFPhone2; property Mobile: String read FMobile write SetFMobile; property Fax: String read FFax write SetFFax; property EMail1: String read FEMail1 write SetFEMail1; property EMail2: String read FEMail2 write SetFEMail2; property ContactBy: Integer read FContactBy write SetFContactBy; property ContactDate: TDateTime read FContactDate write SetFContactDate; property ContactCreatedBy:Integer read FContactCreatedBy write SetFContactCreatedBy; property MaritalStatus: Integer read FMaritalStatus write SetFMaritalStatus; property MALetter: integer read FMALetter write SetFMALetter; property MAEmail: integer read FMAEmail write SetFMAEmail; property MAFax: integer read FMAFax write SetFMAFax; property MAPhone: integer read FMAPhone write SetMAPhone; property Note: String read FNote write SetFNote; property CustomerList: TObjectList read FCustomerList write SetFCustomerList; property CustomerAddsList: TObjectList read FCustomerAddsList write SetFCustomerAddsList; procedure LoadContact(aID: Integer); procedure AddCustomer(aCustomer: TCustomer); procedure AddCustomerAdds(aCustomerAdds: TContactCustomerAdds); procedure RemoveCustomer(aID: Integer); constructor create; end; implementation { TContact } procedure TContact.AddCustomer(aCustomer: TCustomer); begin FCustomerList.Add(aCustomer); end; procedure TContact.AddCustomerAdds(aCustomerAdds: TContactCustomerAdds); begin FCustomerAddsList.Add(aCustomerAdds); end; constructor TContact.create; begin OQuery1:=TZQuery.Create(nil); OQuery1.Connection:=XForm.XBASDBC; OQuery2:=TZQuery.Create(nil); OQuery2.Connection:=XForm.XBASDBC; FCustomerList:=TObjectList.Create(true); FCustomerAddsList:=TObjectList.Create(true); end; procedure TContact.LoadContact(aID: Integer); var myCustomer: TCustomer; myCustomerAdds: TContactCustomerAdds; begin OQuery1.SQL.Text:='SELECT * FROM kom_ko2000 WHERE id=:id'; OQuery1.ParamByName('id').AsInteger:=aID; OQuery1.Open; If OQuery1.RecordCount > 0 then begin Salutation:=OQuery1.fieldbyname('salutation').AsInteger; Title:=OQuery1.fieldbyname('title').AsInteger; ForeName1:=OQuery1.fieldbyname('fname1').AsString; ForeName2:=OQuery1.fieldbyname('fname2').AsString; ForeName1:=OQuery1.fieldbyname('fname1').AsString; LastName:=OQuery1.fieldbyname('lname').AsString; Birthdate:=OQuery1.fieldbyname('birthdate').AsDateTime; Street:=OQuery1.fieldbyname('street').AsString; Postal:=OQuery1.fieldbyname('postal').AsString; City:=OQuery1.fieldbyname('city').AsString; Region:=OQuery1.fieldbyname('region').AsString; Country:=OQuery1.fieldbyname('country').AsInteger; AddNote:=OQuery1.fieldbyname('addnote').AsString; Phone1:=OQuery1.fieldbyname('phone1').AsString; Phone2:=OQuery1.fieldbyname('phone2').AsString; Mobile:=OQuery1.fieldbyname('mobile').AsString; Fax:=OQuery1.fieldbyname('fax').AsString; EMail1:=OQuery1.fieldbyname('email1').AsString; EMail2:=OQuery1.fieldbyname('email2').AsString; ContactBy:=OQuery1.fieldbyname('contactby').AsInteger; ContactDate:=OQuery1.fieldbyname('contactdate').AsDateTime; ContactCreatedBy:=OQuery1.fieldbyname('contactcreatedby').AsInteger; MaritalStatus:=OQuery1.fieldbyname('maritalstatus').AsInteger; MALetter:=OQuery1.fieldbyname('maletter').AsInteger; MAEmail:=OQuery1.fieldbyname('maemail').AsInteger; MAFax:=OQuery1.fieldbyname('mafax').AsInteger; MAPhone:=OQuery1.fieldbyname('maphone').AsInteger; Note:=OQuery1.fieldbyname('note').AsString; // Customer zu Contact laden CustomerList.Clear; OQuery1.SQL.Text:='SELECT c.id FROM kom_ko3000 cc JOIN kom_ko1000 c ON c.id = cc.custid WHERE cc.contactid=:contactid ORDER BY c.name1 ASC'; OQuery1.ParamByName('contactid').AsInteger:=ContactID; OQuery1.Open; While not OQuery1.Eof do begin myCustomer:=TCustomer.Create; myCustomer.LoadCustomer(OQuery1.fieldbyname('id').AsInteger); AddCustomer(myCustomer); // Kundenspezifische Informationen zum Kontakt laden OQuery2.SQL.Text:='SELECT * FROM kom_ko3010 WHERE custid=:custid AND contactid=:contactid'; OQuery2.ParamByName('custid').AsInteger:=OQuery1.fieldbyname('id').AsInteger; OQuery2.ParamByName('contactid').AsInteger:=ContactID; OQuery2.Open; myCustomerAdds:=TContactCustomerAdds.create; myCustomerAdds.FCustomerID:=OQuery1.fieldbyname('id').AsInteger; myCustomerAdds.FPhone1:=OQuery2.fieldbyname('phone1').AsString; AddCustomerAdds(myCustomerAdds); OQuery2.Close; // ================================================= OQuery1.Next; end; // ==================================================================== end; OQuery1.Close; end; xMAIN in der uses-Klausel ist mein Core-Modul in meinem Projekt (da steht quasi die DB-Verbindung drin), xForm ist die Main-Form meines Anwendungssystems. Du könntest auch das OnCreate-Event überschreiben und als Parameter Deine ZConnection mitgeben, damit Du dann die DB-Connection hast. In der Unit gibt es 2 Klassen: 1. TContact und 2. TContactCustomerAdds (das sind zusätzliche Firmeninfos zu einem Kontakt [bei mir eine Person]. Eine Person kann bei mir in mehreren Firmen aktiv sein). Dann wird weiter unten noch die Klasse TCustomer verwendet, die analog "Firmen-Objekte" abbildet. Die o.g. Unit bindest Du in Deine Mainform ein. Entweder benutzt Du dann eine globale Variable "Kontakt", die vom Typ TContact ist, oder Du erstellst diese in den jeweiligen Proceduren, wo Du mit Kontaktdaten arbeitest. Gruß Igotcha |
Re: Projekt "kopieren"
Zitat:
Vielen Dank für die Mühe und die verständlichen Antworten an alle, insbesondere an Igotcha :hi: MfG davar |
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:07 Uhr. |
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