Ich möchte einfach x Worksheets in einem Workbook erzeugen und vorher alles löschen. Später soll dann das Workbook auch gespeichert werden.
Mein Ansatz, eine Workbooksource die mit allen verbunden ist. Wenn ich auf den Button drücke, dann soll alles (Memoryleakfrei) gelöscht werden und die neuen Sheets erzeugt werden. Aktuell ist das ein absolutes Minimalbeispiel.
Code: Alles auswählen
unit uSheets;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
fpspreadsheetctrls, fpspreadsheetgrid;
type
{ TForm1 }
TForm1 = class(TForm)
BuCreateSheets: TButton;
sWorkbookSource: TsWorkbookSource;
sWorkbookTabControl: TsWorkbookTabControl;
sWorksheetGrid: TsWorksheetGrid;
procedure BuCreateSheetsClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.BuCreateSheetsClick(Sender: TObject);
var
i: Integer;
strWsName: String;
begin
// Clear all old sheets
sWorkbookSource.Workbook.RemoveAllWorksheets;
// Create 6 Sheets with different name
for i:= 0 to 5 do begin
strWsName := 'WS'+IntToStr(i+1);
sWorkbookSource.Workbook.AddWorksheet(strWsName,False);
end;
end;
end.
Erstens sehe ich das erste Sheet 2x, und beim 2ten versuch gibt ein DeadBeef

Schalte ich alle Debuggingabfragen ein, so kracht es bei
Code: Alles auswählen
#0 UTF8TOUTF16(0xf0f0f0f0 <error: Cannot access memory at address 0xf0f0f0f0>, 0x2abfdf4 'WS1') at lazutf8.pas:3734
#1 UTF8COMPARETEXT(0xf0f0f0f0 <error: Cannot access memory at address 0xf0f0f0f0>, 0x2abf734 'WS1') at lazutf8.pas:3344
#2 TSWORKBOOK__GETWORKSHEETBYNAME(0x2abf734 'WS1', <error reading variable>) at .\common\fpspreadsheet.pas:8760
#3 TSWORKBOOK__VALIDWORKSHEETNAME(0x2abf734 'WS1', false, <error reading variable>) at .\common\fpspreadsheet.pas:8892
#4 TSWORKBOOK__ADDWORKSHEET(0x2abf734 'WS1', false, <error reading variable>) at .\common\fpspreadsheet.pas:8549
#5 TFORM1__BUCREATESHEETSCLICK(0x2c48868, <error reading variable>) at usheets.pas:46
#6 TCONTROL__CLICK(<error reading variable>) at .\include\control.inc:2850
#7 TBUTTONCONTROL__CLICK(<error reading variable>) at .\include\buttoncontrol.inc:55
#8 TCUSTOMBUTTON__CLICK(<error reading variable>) at .\include\buttons.inc:169
#9 TBUTTONCONTROL__WMDEFAULTCLICKED({MSG = 66567, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, WPARAMFILLER = {}, LPARAMLO = 0, LPARAMHI = 0, LPARAMFILLER = {}, RESULTLO = 0, RESULTHI = 0, RESULTFILLER = {}}, <error reading variable>) at .\include\buttoncontrol.inc:21
#10 SYSTEM$_$TOBJECT_$__$$_DISPATCH$formal at :0
#11 ?? at :0
#12 TWINCONTROL__WNDPROC({MSG = 66567, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, WPARAMFILLER = {}, LPARAMLO = 0, LPARAMHI = 0, LPARAMFILLER = {}, RESULTLO = 0, RESULTHI = 0, RESULTFILLER = {}}, <error reading variable>) at .\include\wincontrol.inc:5396
#13 DELIVERMESSAGE(0x2c48868, <error reading variable: Attempt to dereference a generic pointer.>) at lclmessageglue.pas:112
#14 TWINDOWPROCHELPER__DOWINDOWPROC(<error reading variable>) at .\win32\win32callback.inc:2496
#15 WINDOWPROC(134848, 273, 34920, 134856) at .\win32\win32callback.inc:2654
#16 CUSTOMFORMWNDPROC(134848, 273, 34920, 134856) at .\win32\win32wsforms.pp:386
#17 USER32!AddClipboardFormatListener at :0
#18 USER32!DispatchMessageW at :0
#19 USER32!SendMessageW at :0
#20 USER32!SendMessageW at :0
#21 CreateMappedBitmap at :0
#22 DetachScrollBars at :0
#23 USER32!AddClipboardFormatListener at :0
#24 USER32!DispatchMessageW at :0
#25 USER32!CallWindowProcW at :0
#26 CALLDEFAULTWINDOWPROC(134856, 514, 0, 983106) at .\win32\win32callback.inc:97
#27 TWINDOWPROCHELPER__DOWINDOWPROC(<error reading variable>) at .\win32\win32callback.inc:2404
#28 WINDOWPROC(134856, 514, 0, 983106) at .\win32\win32callback.inc:2654
#29 BUTTONWNDPROC(134856, 514, 0, 983106) at .\win32\win32wsstdctrls.pp:1603
#30 USER32!AddClipboardFormatListener at :0
#31 USER32!DispatchMessageW at :0
#32 USER32!DispatchMessageW at :0
#33 USER32!DispatchMessageW at :0
#34 TWIN32WIDGETSET__APPPROCESSMESSAGES(<error reading variable>) at .\win32\win32object.inc:407
#35 TAPPLICATION__HANDLEMESSAGE(<error reading variable>) at .\include\application.inc:1276
#36 TAPPLICATION__RUNLOOP(<error reading variable>) at .\include\application.inc:1413
#37 TWIDGETSET__APPRUN(0x425e50 <TAPPLICATION__RUNLOOP>, <error reading variable>) at .\include\interfacebase.inc:54
#38 TAPPLICATION__RUN(<error reading variable>) at .\include\application.inc:1401
#39 main at MoreSheets.lpr:19
Irgendwie habe ich das Gefühl einen kapitalen Hirsch zu schiessen, aber die beiden Wiki's zu fpspreadsheet haben mich da auch nicht weitergebracht und bei dem Beispielen habe ich nicht verwertbares gefunden.
Andreas