Autor Beitrag
Fredy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57

Win Vista Ultimate

BeitragVerfasst: Mo 18.05.09 17:31 
Hallo liebe Community,

Ich habe eine Combobox mit Artikeln diese Artikel möchte ich bei bestätigen des Buttons in ein Array laden.

z.B. ich wähle z.B. Maus in der Combobox dann soll in meinem Warenkorbartikel ( Mein Array ) in der ersten Zeile die Maus stehen.

ausblenden Delphi-Quelltext
1:
Warenkorbartikel : Array of shortstring;					



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TfrmRAEingabe.btnStartClick(Sender: TObject);
var k: integer;
begin

SetLength(Warenkorbartikel, 15);


for k := 0 to high(Warenkorbartikel) do
    begin
      Warenkorbartikel[k] := cbArtikel.Text;
      exit;
    end// von for

end;


Ich glaube ich mache einen Denkfehler schon mal Vielen Dank für eure Antworten.


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Mo 18.05.2009 um 17:59
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 18.05.09 17:45 
Moin!

user profile iconFredy hat folgendes geschrieben Zum zitierten Posting springen:
Ich habe eine Combobox mit Artikeln diese Artikel möchte ich bei bestätigen des Buttons in ein Array laden.
Die entscheidende Frage ist:
user profile iconFredy hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
Warenkorbartikel : Array of shortstring;					
Soll dein Warenkorb immer eine feste Größe haben (dann brauchst du einen Füllmengenzeiger) oder soll er dynamisch "wachsen" (dann musst du die Länge des dyn. Arrays anpassen)? :nixweiss:

user profile iconFredy hat folgendes geschrieben Zum zitierten Posting springen:
z.B. ich wähle z.B. Maus in der Combobox dann soll in meinem Warenkorbartikel ( Mein Array ) in der ersten Zeile die Maus stehen.
Aber doch erst nach dem Buttonklick, oder? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.


Zuletzt bearbeitet von Narses am Mo 18.05.09 18:13, insgesamt 1-mal bearbeitet
Fredy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57

Win Vista Ultimate

BeitragVerfasst: Mo 18.05.09 17:51 
besser wäre es wenn es dynamisch ist ;) Aber wie musss ich das jetzt umsetzten ?

Dann müsste ich sozusagen die Länge bei jedem Klick einmal erhöhen oder ?

Ja erst beim Buttonklick soll er die Combobox einlesen.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 18.05.09 17:56 
Moin!

user profile iconFredy hat folgendes geschrieben Zum zitierten Posting springen:
besser wäre es wenn es dynamisch ist ;) Aber wie musss ich das jetzt umsetzten ?
Dann wäre der Ablauf in etwa so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  Warenkorbartikel : Array of shortstring;

// bei Programmstart
Warenkorbartikel := NIL// nix drin

// beim Klick "Hinzufügen"
SetLength(Warenkorbartikel,Length(Warenkorbartikel) +1); // ein Element mehr
Warenkorbartikel[High(Warenkorbartikel)] := ComboBox1.Text; // Element dazu tun
Das dyn. Array auf diese Weise anzufassen ist nicht grade "Speichersparend", aber für ein einfaches Programm mit wenig Einträgen ist das schon OK. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Fredy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57

Win Vista Ultimate

BeitragVerfasst: Mo 18.05.09 18:05 
okay so weit so gut wenn ich aber das Programm schließe und wieder öffne dann ist der Warenkorb wieder auf Null gesetzt und er überschreibt mir die ersten Artikel wieder oder ?
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 18.05.09 18:08 
Sicher, Du wirst ihn schon speichern müssen.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 18.05.09 18:09 
Moin!

user profile iconFredy hat folgendes geschrieben Zum zitierten Posting springen:
wenn ich aber das Programm schließe und wieder öffne dann ist der Warenkorb wieder auf Null gesetzt und er überschreibt mir die ersten Artikel wieder oder ?
Klar :nixweiss: wir haben ja auch nicht über das Speichern dieses Warenkorb-Arrays gesprochen, sondern über die Benutzung. ;)

Wenn du den Warenkorb auch speichern/laden sollst, dann würde ich aber besser eine TStringList nehmen, die kann mit den Methoden .LoadFromFile() und .SaveToFile() schon sowas. :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Fredy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57

Win Vista Ultimate

BeitragVerfasst: Mo 18.05.09 18:10 
das ist verständlich aber dann dürfte ich den Warenkorb ja nicht auf null setzten beim Programmstart.

Weil der gespeicherte Datensatz im Warenkorb soll ja nicht überschrieben werden sondern soll unten drunter weitergeführt werden nach einem neustart oder ?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 18.05.09 18:13 
Moin!

user profile iconFredy hat folgendes geschrieben Zum zitierten Posting springen:
das ist verständlich aber dann dürfte ich den Warenkorb ja nicht auf null setzten beim Programmstart.
Doch, das würde ich schon tun, allerdings würde ich danach versuchen, einen schon existierenden Warenkorb zu laden. ;) Das Programm muss ja auch einen definierten Anfangszustand haben (das allererste Mal gibt´s ja noch gar keinen Warenkorbinhalt). :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Fredy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57

Win Vista Ultimate

BeitragVerfasst: Mo 18.05.09 22:17 
Hallo liebe Community,

hab es super hinbekommen dank eurer hilfe nur stehe ich jetzt vor einem Problem und zwar hab ich eine Speichern Funktion eingebaut.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
//------------------------------------------------------------------------------
// Die Datensätze im Array werden dauerhaft in einer Datei gespeichert
//------------------------------------------------------------------------------
procedure ArrayInDateiW();
var k: integer;
begin
  rewrite(WarenkorbDatei);
  Seek(WarenkorbDatei, 0);
  for k := 0 to high(Warenkorbartikel) do
    begin
      WarenkorbSatz := Warenkorbartikel[k];
      Write(WarenkorbDatei, WarenkorbSatz);
    end// von for
  CloseFile(WarenkorbDatei);
end// der Prozedur
//------------------------------------------------------------------------------
//--------------------------- Warenkorb Ende -----------------------------------
//------------------------------------------------------------------------------


Variabeldeklaration:

ausblenden Delphi-Quelltext
1:
2:
3:
  WarenkorbSatz                : WarenkorbRecord;   // Recordvariable
  WarenkorbDatei               : WarenkorbFile;     // Dateivariable
  Warenkorbartikel             : Array of shortstring;


Das will Delphie aber leider nicht annehmen er gibt eine Fehlermeldung aus und zwar diese :

[Error] dateien.inc(824): Incompatible types: 'WarenkorbRecord' and 'ShortString'

Weiß jemand wie ich den Fehler beheben kann ?


Mfg. Fredy

Edit:

ausblenden Delphi-Quelltext
1:
  Warenkorbartikel             : Array of WarenkorbRecord;					


hab dies jetzt so geändert aber jetzt Funktioniert das mit dem Artikel hinzufügen nicht ;)

ausblenden Delphi-Quelltext
1:
  Warenkorbartikel[High(Warenkorbartikel)] := cbArtikel.Text;					


Fehlermeldung: [Error] Unit19.pas(238): Incompatible types: 'WarenkorbRecord' and 'TCaption'

Edit2: okay das was ich bei Edit ausprobiert habe kann man nicht machen dann bekomme ich noch mehr Fehlermeldungen
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 18.05.09 22:40 
Moin!

Wie ist den WarenkorbRecord deklariert (und warum)? :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Fredy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57

Win Vista Ultimate

BeitragVerfasst: Mo 18.05.09 22:48 
das hab ich so

ausblenden Delphi-Quelltext
1:
2:
3:
  type WarenkorbRecord      = record
  end;
  WarenkorbFile             = file of WarenkorbRecord;


das hab ich aus einer Vorlage ;) hab nicht genau gewust wie ich das umsetzten soll
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 18.05.09 22:51 
Moin!

user profile iconFredy hat folgendes geschrieben Zum zitierten Posting springen:
das hab ich so

ausblenden Delphi-Quelltext
1:
2:
3:
  type WarenkorbRecord      = record
  end;
  WarenkorbFile             = file of WarenkorbRecord;


das hab ich aus einer Vorlage ;) hab nicht genau gewust wie ich das umsetzten soll
:hair: Ähm :? kennst du das hier schon? Wenn nicht, bitte mal kurz durchlesen... :|

Diese record-Deklaration und das File of desselben sind komplett nutzlos. Am besten machst du das mit dem Warenkorb als TStringList, das ist deutlich einfacher. :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Fredy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57

Win Vista Ultimate

BeitragVerfasst: Mo 18.05.09 22:54 
du hast nicht zufällig eine Idee wie ich das hinbekomme mit meiner bisherigen Ausgangsposition ?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 18.05.09 23:06 
Moin!

ausblenden Delphi-Quelltext
1:
2:
type
  WarenkorbFile = file of ShortString;
Aber ich fürchte, du hast nicht den leisesten Plan, was hier eigentlich läuft... :(

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Fredy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57

Win Vista Ultimate

BeitragVerfasst: Mo 18.05.09 23:10 
da hast du Recht aber ich möchte es irgendwie heute noch zum laufen bringen =)

gleiche Fehlermeldung immer noch:

Fehlermeldung: [Error] Unit19.pas(238): Incompatible types: 'WarenkorbRecord' and 'TCaption'

ausblenden Delphi-Quelltext
1:
 Warenkorbartikel[High(Warenkorbartikel)] := cbArtikel.Text;					


hat jemand eine Idee bin gerade ein bisschen am Verzweifeln ?
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Mo 18.05.09 23:28 
Da müssen wir uns eben mal etwas sputen:
ausblenden Delphi-Quelltext
1:
Warenkorbartikel : array of ShortString;					

Du musst das so wählen, wenn du diese Zuweisung machen willst. Ich bezweifle aber, dass du die Grundlagen fürs Weiterprogrammieren hast :|