Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Brauch mal Hilfe bei Tobjectlist (https://www.delphipraxis.net/173670-brauch-mal-hilfe-bei-tobjectlist.html)

Natcree 9. Mär 2013 22:35

Brauch mal Hilfe bei Tobjectlist
 
was ist hier falsch wenn ich in form7 mein Button zur eingabe mache dann schmeisst er mich mit fehler raus und vermeist mich auf
Delphi-Quellcode:
if form7.showmodal = ......
raus hier mal der code

Delphi-Quellcode:
if Form7.Showmodal = mrOK then //diese Zeile wird blau markiert
    begin
      FObjects1.Add(Form7.Irgendwas1);
      FGesamt1 := FGesamt1 + Form7.Irgendwas1.Summe1;
      eltreestringgrid1.Cells[3, eltreestringgrid1.Row] := Form7.Irgendwas1.ErsteZahl1AsString + ' €';
      eltreestringgrid1.cells[4, eltreestringgrid1.Row] := form7.Irgendwas1.ZweiteZahl1AsString + ' €';
      eltreestringgrid1.Cells[4, eltreestringgrid1.Row] := Format('%.2n €', [FGesamt]);
      eltreestringgrid1.Cells[4, eltreestringgrid1.Row-1]:=form1.eltreestringgrid1.Cells[4,form1.eltreestringgrid1.Row-1]+' €';
      eltreestringgrid1.RowCount := eltreestringgrid1.RowCount + 1;
      eltreestringgrid1.Row := eltreestringgrid1.Row + 1;
      FObjects.Add(Form7.Irgendwas);
      FGesamt := FGesamt + Form7.Irgendwas.Summe;
      eltreestringgrid1.Cells[2, eltreestringgrid1.Row] := Form7.Irgendwas.ErsteZahlAsString + ' €';
      eltreestringgrid1.cells[4, eltreestringgrid1.Row] := form7.Irgendwas.ZweiteZahlAsString + ' €';
      eltreestringgrid1.Cells[4, eltreestringgrid1.Row] := Format('%.2n €', [FGesamt]);
      eltreestringgrid1.Cells[4, eltreestringgrid1.Row-1]:=form1.eltreestringgrid1.Cells[4,form1.eltreestringgrid1.Row-1]+' €';
      eltreestringgrid1.RowCount := eltreestringgrid1.RowCount + 1;
      eltreestringgrid1.Row := eltreestringgrid1.Row + 1;
     end;
end;

Natcree 9. Mär 2013 22:49

AW: Brauch mal Hilfe bei Tobjectlist
 
Liste der Anhänge anzeigen (Anzahl: 1)
hier mal ein bild

Bjoerk 10. Mär 2013 00:02

AW: Brauch mal Hilfe bei Tobjectlist
 
Weise dem Button im OI das ModalResult MrOk zu und formuliere:

Delphi-Quellcode:
  if ModalResult = mrOK then

Natcree 10. Mär 2013 00:08

AW: Brauch mal Hilfe bei Tobjectlist
 
wo mache ich das im oi finde da nichts ist ein speed button

Natcree 10. Mär 2013 00:18

AW: Brauch mal Hilfe bei Tobjectlist
 
habe nen anderen button genommen kommt immer noch fehler

Volker Z. 10. Mär 2013 00:25

AW: Brauch mal Hilfe bei Tobjectlist
 
Hallo,

vermutlich scheppert es bereits irgendwo in Form7 und die Exception wird nur bis an die "blau markierte" Stelle im Programmcode "durchgereicht". Was passiert den in Form7? Quellcode wäre hilfreich.

Gruß

Natcree 10. Mär 2013 00:28

AW: Brauch mal Hilfe bei Tobjectlist
 
Delphi-Quellcode:
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ElPanel, ElClock, LMDBaseControl,
  LMDBaseGraphicControl, LMDGraphicControl, LMDLEDCustomLabel, LMDLEDLabel,
  LMDControl, LMDCustomControl, LMDCustomPanel, LMDCustomBevelPanel,
  LMDBaseEdit, LMDCustomEdit, LMDCustomMaskEdit, LMDCalculatorEdit,
  ElPgCtl, ElXPThemedControl, LMDCalendarEdit, ComCtrls,
  LMDCustomShapeButton, LMDShapeButton, LMDBaseGraphicButton,
  LMDCustomMMButton, LMDMMButton, StdCtrls, LMDCustomButton, LMDButton,
  ElComponent, ElCalc, ElEdits, ElBtnEdit, ElCalculatorEdit,
  LMDCustomExtCombo, LMDCalculatorComboBox,
  LMDDBCalculatorComboBox, DBCtrls, Mask, Buttons, Grids,comobj,
  ElTreeInplaceEditors, ElTree, ElTreeGrids,uSharedClass;

type
  TForm7 = class(TForm)
    ElPageControl1: TElPageControl;
    ElTabSheet1: TElTabSheet;
    ElTabSheet2: TElTabSheet;
    LMDShapeButton1: TLMDShapeButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    LMDShapeButton2: TLMDShapeButton;
    Button1: TButton;
    Button2: TButton;
    Label6: TLabel;
    Label7: TLabel;
    LMDShapeButton3: TLMDShapeButton;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    LMDShapeButton4: TLMDShapeButton;
    SpeedButton1: TSpeedButton;
    DateTimePicker1: TDateTimePicker;
    SpeedButton2: TSpeedButton;
    DateTimePicker2: TDateTimePicker;
    Edit1: TEdit;
    Edit2: TEdit;
    Memo1: TMemo;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Memo2: TMemo;
    Edit7: TEdit;
    Edit8: TEdit;
    Button3: TButton;
    Label11: TLabel;
    StringGrid1: TStringGrid;
    Edit9: TEdit;

    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure DateTimePicker1Change(Sender: TObject);
    procedure DateTimePicker2Change(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure LMDDBCalculatorComboBox2Change(Sender: TObject);
    procedure LMDDBCalculatorComboBox1Change(Sender: TObject);
    procedure LMDShapeButton1Click(Sender: TObject);
    procedure LMDShapeButton3Click(Sender: TObject);
    procedure LMDShapeButton4Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure LMDShapeButton2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ElPageControl1Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormDestroy(Sender: TObject);
    procedure Button3Click(Sender: TObject);

  private
    { Private declarations }
     FIrgendwas: TIrgendwas;
     FIrgendwas1: TIrgendwas1;
  public
    { Public declarations }

     property Irgendwas: TIrgendwas read FIrgendwas;
     property Irgendwas1: TIrgendwas1 read FIrgendwas1;
  end;
var
  Form7: TForm7;

implementation

uses Unit1, Unit8;

{$R *.dfm}


procedure TForm7.FormCreate(Sender: TObject);
begin
elpagecontrol1.ActivePageIndex:=0;
datetimepicker1.DateTime := now;
edit1.Text:='';
edit4.Text:='';
edit3.Text:='';
edit2.Text:='';
memo1.Text:='';

End;

function Xls_To_StringGrid(AGrid: TeltreeStringGrid; AXLSFile: string): Boolean;
const
xlCellTypeLastCell = $0000000B;
var
XLApp, Sheet: OLEVariant;
RangeMatrix: Variant;
x, y, k, r: Integer;
begin
Result := False;
XLApp := CreateOleObject('Excel.Application');
try
XLApp.Visible := False;
XLApp.Workbooks.Open(AXLSFile);
Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
x := XLApp.ActiveCell.Row;
y := XLApp.ActiveCell.Column;
AGrid.RowCount := x;
AGrid.ColCount := y;
RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;
k := 1;
repeat
for r := 1 to y do
AGrid.Cells[(r ), (k )] := RangeMatrix[K, R];
Inc(k, 1);
AGrid.RowCount := k + 1;
until k > x;
RangeMatrix := Unassigned;
finally
if not VarIsEmpty(XLApp) then
begin
XLApp.Quit;
XLAPP := Unassigned;
Sheet := Unassigned;
Result := True;
end;
end;
end;
function RefToCell(ARow, ACol: Integer): string;
begin
Result := Chr(Ord('A') + ACol - 1) + IntToStr(ARow);
end;
function SaveAsExcelFile1(AGrid: TStringGrid; ASheetName, AFileName: string): Boolean;
const
xlWBATWorksheet = -4167;
var
XLApp, Sheet, Data: OLEVariant;
i, j: Integer;
begin
// Prepare Data
Data := VarArrayCreate([1, AGrid.RowCount, 1, AGrid.ColCount], varVariant);
for i := 0 to AGrid.ColCount - 1 do
for j := 0 to AGrid.RowCount - 1 do
Data[j + 1, i + 1] := AGrid.Cells[i, j];
// Create Excel-OLE Object
Result := False;
XLApp := CreateOleObject('Excel.Application');
try
// Hide Excel
XLApp.Visible := False;
// Add new Workbook
XLApp.Workbooks.Add(xlWBatWorkSheet);
Sheet := XLApp.Workbooks[1].WorkSheets[1];
Sheet.Name := ASheetName;
// Fill up the sheet
Sheet.Range[RefToCell(1, 1), RefToCell(AGrid.RowCount,
AGrid.ColCount)].Value := Data;
// Save Excel Worksheet
try
XLApp.Workbooks[1].SaveAs(AFileName);
Result := True;
except
// Error ?
end;
finally
// Quit Excel
if not VarIsEmpty(XLApp) then
begin
XLApp.DisplayAlerts := False;
XLApp.Quit;
XLAPP := Unassigned;
Sheet := Unassigned;
end;
end;
end;
function SaveAsExcelFile(AGrid: Teltreestringgrid; ASheetName, AFileName: string): Boolean;
const
xlWBATWorksheet = -4167;
var
 Col: Integer;
GridPrevFile: string;
XLApp, Sheet, Data: OLEVariant;
i, j: Integer;
begin
// Prepare Data
Data := VarArrayCreate([1, AGrid.RowCount, 1, AGrid.ColCount], varVariant);
for i := 0 to AGrid.ColCount - 1 do
for j := 0 to AGrid.RowCount - 1 do
Data[j + 1, i + 1] := AGrid.Cells[i, j];
// Create Excel-OLE Object
Result := False;
XLApp := CreateOleObject('Excel.Application');
try
// Hide Excel
XLApp.Visible := False;
// Add new Workbook
XLApp.Workbooks.Add(xlWBatWorkSheet);
Sheet := XLApp.Workbooks[1].WorkSheets[1];
Sheet.Name := ASheetName;
// Fill up the sheet
Sheet.Range[RefToCell(1, 1), RefToCell(AGrid.RowCount,
AGrid.ColCount)].Value := Data;
// Save Excel Worksheet
try
XLApp.Workbooks[1].SaveAs(AFileName);
Result := True;
except
// Error ?
end;
finally
// Quit Excel
if not VarIsEmpty(XLApp) then
begin
XLApp.DisplayAlerts := False;
XLApp.Quit;
XLAPP := Unassigned;
Sheet := Unassigned;
end;
end;
end;

procedure TForm7.Button1Click(Sender: TObject);
begin
close;
end;

procedure TForm7.SpeedButton1Click(Sender: TObject);
begin
datetimepicker1.Visible:=true;
DateTimePicker1.Perform(WM_KEYDOWN, VK_F4, 0);
end;

procedure TForm7.DateTimePicker1Change(Sender: TObject);
begin
datetimepicker1.Visible:=false;
edit5.Text:=datetostr(datetimepicker1.Date);
end;

procedure TForm7.DateTimePicker2Change(Sender: TObject);
begin
datetimepicker2.Visible:=false;
edit1.Visible:=true;
edit1.Text:=datetostr(datetimepicker2.Date);
end;

procedure TForm7.SpeedButton2Click(Sender: TObject);
begin
edit1.Visible:=false;
datetimepicker2.Visible:=true;
DateTimePicker2.Perform(WM_KEYDOWN, VK_F4, 0);
end;

procedure TForm7.LMDDBCalculatorComboBox2Change(Sender: TObject);
begin
edit3.Text:='';
end;

procedure TForm7.LMDDBCalculatorComboBox1Change(Sender: TObject);
begin
edit3.text:='';
end;

function Xls_To_StringGrid1(AGrid: TStringGrid; AXLSFile: string): Boolean;
const
xlCellTypeLastCell = $0000000B;
var
XLApp, Sheet: OLEVariant;
RangeMatrix: Variant;
x, y, k, r: Integer;
begin
Result := False;
XLApp := CreateOleObject('Excel.Application');
try
XLApp.Visible := False;
XLApp.Workbooks.Open(AXLSFile);
Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
x := XLApp.ActiveCell.Row;
y := XLApp.ActiveCell.Column;
AGrid.RowCount := x;
AGrid.ColCount := y;
RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;
k := 1;
repeat
for r := 1 to y do
AGrid.Cells[(r-1 ), (k-1 )] := RangeMatrix[K, R];
Inc(k, 1);
AGrid.RowCount := k + 1;
until k > x;
RangeMatrix := Unassigned;
finally
if not VarIsEmpty(XLApp) then
begin
XLApp.Quit;
XLAPP := Unassigned;
Sheet := Unassigned;
Result := True;
end;
end;
end;
procedure TForm7.LMDShapeButton1Click(Sender: TObject);
begin
form8.Label2.Caption:='';
form8.show;
end;

procedure TForm7.LMDShapeButton3Click(Sender: TObject);
begin
form8.Label2.Caption:='a';
form8.show;
end;

procedure TForm7.LMDShapeButton4Click(Sender: TObject);
var
    i,p : integer;
begin
  repeat
 form1.eltreeStringGrid1.Cols[1]; // die 2. Spalte

     p := form1.eltreeStringGrid1.Cols[1].IndexOf('1'); // suche nach "rot"
     if p >= 0 then
     edit8.Text:=inttostr(p+1); // ersetzen
   until p < 0;
 end;



procedure TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if ModalResult <> mrOK then
    FreeAndNil(FIrgendwas);
    if ModalResult <> mrOK then
    FreeAndNil(FIrgendwas1);
end;

procedure TForm7.LMDShapeButton2Click(Sender: TObject);
var
i,k : integer;
begin
for i:=0 to form1.eltreestringgrid1.rowcount-1 do begin //reihenbis zur letzten durchsuchen
if form1.eltreeStringGrid1.Cells[1,i]=''//wenn spalte 2 leer ist dann
then edit4.text:='1'// edit4.text ist gleich die zahl 1
else //sonst
k:=strtoint(form1.eltreeStringGrid1.Cells[1,i]); // k ist die gefundene Zahl in der zelle
edit4.text:=inttostr(k+1); // edit4.text ist dann die gefundene Zahl + 1
end;
end;

procedure TForm7.FormShow(Sender: TObject);
begin
edit9.Text:=form1.ElTreeStringGrid1.Cells[4,form1.ElTreeStringGrid1.Row-1];
FIrgendwas := TIrgendwas.Create;
if label11.caption='' then elpagecontrol1.ActivePageIndex:=0;
if elpagecontrol1.ActivePageIndex=1 then button2.Visible:=false;
if elpagecontrol1.ActivePageIndex=1 then button3.Visible:=true;
if elpagecontrol1.ActivePageIndex=0 then button3.Visible:=false;
if elpagecontrol1.ActivePageIndex=0 then button2.Visible:=true;

end;

procedure TForm7.ElPageControl1Change(Sender: TObject);
begin
if elpagecontrol1.ActivePageIndex=1 then button2.Visible:=false;
if elpagecontrol1.ActivePageIndex=1 then button3.Visible:=true;
if elpagecontrol1.ActivePageIndex=0 then button3.Visible:=false;
if elpagecontrol1.ActivePageIndex=0 then button2.Visible:=true;
end;

procedure TForm7.Button2Click(Sender: TObject);
begin

  form1.eltreestringgrid1.cells[0,form1.ElTreeStringGrid1.Row]:=edit1.text;
  try
    FIrgendwas.ErsteZahlAsString := edit3.Text;
      try
        FIrgendwas.ZweiteZahlAsString := edit9.text;
        ModalResult := mrOK;
    except
      on E: Exception do
        begin
          MessageBox(0, PChar(E.Message), nil, MB_OK or MB_ICONERROR);
          edit9.SetFocus;
          edit9.SelectAll;
        end;
    end;
  except
    on E: Exception do
      begin
        MessageBox(0, PChar(E.Message), nil, MB_OK or MB_ICONERROR);
        edit3.SetFocus;
        edit3.SelectAll;
      end;
  end;

  end;

procedure TForm7.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if ModalResult <> mrOK then
    FreeAndNil(FIrgendwas);
end;

procedure TForm7.FormDestroy(Sender: TObject);
begin
  if ModalResult <> mrOK then
    FreeAndNil(FIrgendwas);
end;

procedure TForm7.Button3Click(Sender: TObject);
begin
  form1.eltreestringgrid1.cells[0,form1.ElTreeStringGrid1.Row]:=edit5.text;
  try
    FIrgendwas1.ErsteZahl1AsString := edit7.Text;
      try
        FIrgendwas1.ZweiteZahl1AsString := edit9.text;
        ModalResult := mrOK;
    except
      on E: Exception do
        begin
          MessageBox(0, PChar(E.Message), nil, MB_OK or MB_ICONERROR);
          edit9.SetFocus;
          edit9.SelectAll;
        end;
    end;
  except
    on E: Exception do
      begin
        MessageBox(0, PChar(E.Message), nil, MB_OK or MB_ICONERROR);
        edit7.SetFocus;
        edit7.SelectAll;
      end;
  end;

  end;

end.

Natcree 10. Mär 2013 00:31

AW: Brauch mal Hilfe bei Tobjectlist
 
müsste an der zweiten objecktlist liegen vorher mit der ersten ging es

Bjoerk 10. Mär 2013 00:39

AW: Brauch mal Hilfe bei Tobjectlist
 
Wenn diese Abfrage #1 in Form1 steht dann ist

Delphi-Quellcode:
  if Form7.Showmodal = mrOK then
soweit in Ordnung.

Sehe mir mal kurz noch form7 an ob ich da was finde..

Bjoerk 10. Mär 2013 00:46

AW: Brauch mal Hilfe bei Tobjectlist
 
Ist FIrgendwas1 erzeugt und was ist eigentlich TIrgendwas?

Natcree 10. Mär 2013 01:04

AW: Brauch mal Hilfe bei Tobjectlist
 
type
TIrgendwas = class

Natcree 10. Mär 2013 01:07

AW: Brauch mal Hilfe bei Tobjectlist
 
type
TIrgendwas1 = class

FIrgendwas1 gehört zu dieser class

Natcree 10. Mär 2013 01:08

AW: Brauch mal Hilfe bei Tobjectlist
 
Zitat:

Zitat von Bjoerk (Beitrag 1206684)
Wenn diese Abfrage #1 in Form1 steht dann ist

Delphi-Quellcode:
  if Form7.Showmodal = mrOK then
soweit in Ordnung.

Sehe mir mal kurz noch form7 an ob ich da was finde..

Ja steht Sie

Natcree 10. Mär 2013 01:09

AW: Brauch mal Hilfe bei Tobjectlist
 
hat er vielleicht probleme damit 2 objecktclassen zu createn und zu bedienen???

hier mal der code von form1

if form7.ShowModal = mrok then
begin
FObjects.Add(Form7.Irgendwas);
FGesamt := FGesamt + Form7.Irgendwas.Summe;
eltreestringgrid1.Cells[2, eltreestringgrid1.Row] := Form7.Irgendwas.ErsteZahlAsString + ' €';
eltreestringgrid1.cells[4, eltreestringgrid1.Row] := form7.Irgendwas.ZweiteZahlAsString + ' €';
eltreestringgrid1.Cells[4, eltreestringgrid1.Row] := Format('%.2n €', [FGesamt]);
eltreestringgrid1.Cells[4, eltreestringgrid1.Row-1]:=form1.eltreestringgrid1.Cells[4,form1.eltreestringgrid1.Row-1]+' €';
eltreestringgrid1.RowCount := eltreestringgrid1.RowCount + 1;
eltreestringgrid1.Row := eltreestringgrid1.Row + 1;
if form7.ShowModal = mrok then
begin
FObjects.Add(Form7.Irgendwas);
Fgesamt1 := FGesamt1 + Form7.irgendwas.summe1;
eltreestringgrid1.Cells[3, eltreestringgrid1.Row] := Form7.Irgendwas.dritteZahlAsString + ' €';
eltreestringgrid1.cells[4, eltreestringgrid1.Row] := form7.Irgendwas.ZweiteZahlAsString + ' €';
eltreestringgrid1.Cells[4, eltreestringgrid1.Row] := Format('%.2n €', [FGesamt]);
eltreestringgrid1.Cells[4, eltreestringgrid1.Row-1]:=form1.eltreestringgrid1.Cells[4,form1.eltreestringgrid1.Row-1]+' €';
eltreestringgrid1.RowCount := eltreestringgrid1.RowCount + 1;
eltreestringgrid1.Row := eltreestringgrid1.Row + 1;
end;
end;
end;

Volker Z. 10. Mär 2013 02:29

AW: Brauch mal Hilfe bei Tobjectlist
 
Hallo,

also was Du wirklich brauchst ist zunächst mal ein Grundkurs Quelltextformatierung. Eigentlich sollte unter einem solchen Quelltextpost ein Warnhinweis "Vermeiden Sie ein längeres Betrachten dieses Quellcodes, dies kann zu Augenkrebs, sowie anderen irreparablen Schäden oder schwerwiegenden Beeinträchtigungen Ihres Sehvermögens führen." stehen.
Gewöhn Dir dringend eine ordentliche Formatierung an!

Weiterhin: Was sollen die Funktionen:
  • Xls_To_StringGrid
  • Xls_To_StringGrid1
  • SaveAsExcelFile
  • SaveAsExcelFile1
im Code, wenn sie doch nicht genutzt werden?

Dein Problem liegt wohl hier
Delphi-Quellcode:
procedure TForm7.Button3Click(Sender: TObject);
begin
  form1.eltreestringgrid1.cells[0,form1.ElTreeStringGrid1.Row]:=edit5.text;
  try
    FIrgendwas1.ErsteZahl1AsString := edit7.Text; // <-- wo zum Henker wird den die Eigenschaft FIrgendwas1 instanziiert? Hol es nach und es funktioniert
      try
        FIrgendwas1.ZweiteZahl1AsString := edit9.text;
        ModalResult := mrOK;
    except
      on E: Exception do
        begin
          MessageBox(0, PChar(E.Message), nil, MB_OK or MB_ICONERROR);
          edit9.SetFocus;
          edit9.SelectAll;
        end;
    end;
  except
    on E: Exception do
      begin
        MessageBox(0, PChar(E.Message), nil, MB_OK or MB_ICONERROR);
        edit7.SetFocus;
        edit7.SelectAll;
      end;
  end;

  end;
Da scheppert es dann auch, wenn Du auf den Button klickst und das Form sich über mrOK verabschiedet.

Weiter scheppern wird es dann
Delphi-Quellcode:
if Form7.Showmodal = mrOK then //diese Zeile wird blau markiert
    begin
      FObjects1.Add(Form7.Irgendwas1);
      FGesamt1 := FGesamt1 + Form7.Irgendwas1.Summe1;
      eltreestringgrid1.Cells[3, eltreestringgrid1.Row] := Form7.Irgendwas1.ErsteZahl1AsString + ' &#8364;';
      eltreestringgrid1.cells[4, eltreestringgrid1.Row] := form7.Irgendwas1.ZweiteZahl1AsString + ' &#8364;';
      eltreestringgrid1.Cells[4, eltreestringgrid1.Row] := Format('%.2n &#8364;', [FGesamt]);
      eltreestringgrid1.Cells[4, eltreestringgrid1.Row-1]:=form1.eltreestringgrid1.Cells[4,form1.eltreestringgrid1.Row-1]+' &#8364;';
      eltreestringgrid1.RowCount := eltreestringgrid1.RowCount + 1;
      eltreestringgrid1.Row := eltreestringgrid1.Row + 1;
      FObjects.Add(Form7.Irgendwas);
      FGesamt := FGesamt + Form7.Irgendwas.Summe; // <-- hier, weil in FormCloseQuery freigegeben und zur Sicherheit nochmals in FormClose
      eltreestringgrid1.Cells[2, eltreestringgrid1.Row] := Form7.Irgendwas.ErsteZahlAsString + ' &#8364;';
      eltreestringgrid1.cells[4, eltreestringgrid1.Row] := form7.Irgendwas.ZweiteZahlAsString + ' &#8364;';
      eltreestringgrid1.Cells[4, eltreestringgrid1.Row] := Format('%.2n &#8364;', [FGesamt]);
      eltreestringgrid1.Cells[4, eltreestringgrid1.Row-1]:=form1.eltreestringgrid1.Cells[4,form1.eltreestringgrid1.Row-1]+' &#8364;';
      eltreestringgrid1.RowCount := eltreestringgrid1.RowCount + 1;
      eltreestringgrid1.Row := eltreestringgrid1.Row + 1;
     end;
end;
Verstehe es bitte nicht falsch, ich bin immer dafür keine Memoryleaks zu hinterlassen, aber ein FreeAndNil in FormCloseQuery, FormClose und FormDestroy ist ein klein wenig übertrieben.

Ich hoffe es hilft Dir etwas weiter und ich bin ab morgen nicht mit Blindheit geschlagen

Gruß

Natcree 10. Mär 2013 19:46

AW: Brauch mal Hilfe bei Tobjectlist
 
Liste der Anhänge anzeigen (Anzahl: 1)
habe es jetzt hinbekommen. Danke erstmal an alle jetzt habe ich noch eine Frage.

Ich habe 2 objectlisten erstellt einmal für einnahme und einmal für ausgabe für das kassen buch jedoch rechnet er immer mit dem im speicher geladenen Daten siehe Bild. Wie kann ich das am besten ändern???

Bjoerk 10. Mär 2013 21:17

AW: Brauch mal Hilfe bei Tobjectlist
 
Gib deinen Variablen mal vernünftige Bezeichner.

Wahrscheinlich hast du irgendwo ein irgendwas mit irgendwas1 verwechselt oder gar irgendwo irgendwas := irgendwas1 stehen.

Natcree 10. Mär 2013 21:29

AW: Brauch mal Hilfe bei Tobjectlist
 
ich checke es nochmal

kann mann den speicher nicht einfach freigeben so das er wieder bei null anfängt

wenn ich in diesen code
Delphi-Quellcode:
function TIrgendwas.GetSumme: double;
begin
  Result := ferstezahl+fzweitezahl;
end;
wenn es so steht dann rechnet er falsch obwohl dies richtig wäre da fzweitezahl row-1 ist in der spalte bestand. und ferstezahl splate einnahmen

Natcree 10. Mär 2013 21:43

AW: Brauch mal Hilfe bei Tobjectlist
 
habe den Fehler gefunden

Delphi-Quellcode:
Fgesamt1 := FGesamt1 + Form7.irgendwas1.summe1;
habe es geändert

Delphi-Quellcode:
Fgesamt1 := Form7.irgendwas1.summe1;

Danke für den tip manchmal ist mann echt blind....

DeddyH 11. Mär 2013 07:02

AW: Brauch mal Hilfe bei Tobjectlist
 
Nur weil ich die Klasse und die Variable TIrgendwas/Irgendwas genannt habe, muss das ja nicht so bleiben. Das lag einzig und allein daran, dass ich nicht wusste, was da eigentlich dahintersteckt. Es wäre also vielleicht eine gute Idee, die Namen einmal an die tatsächlichen Gegebenheiten anzupassen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:59 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