создал класс, для работы с Excel`ем , в виде модуля(.pas). создал новую форму, подконнектил свой модуль, объявил переменную(cE:cExcel), когда пытаюсь задать параметры(SetExcParams) запуска екселя, начинает ругаться !!!! ((( errmessage: Access violation at address 00453B0C in module 'Test.exe'. Write of address 00000038. в чем проблема и как ее исправить ? подскажите пожалуйса! тело класса: Код | unit uExcel;
interface
const colorGreen = 15007690; colorBlue = 16758380; colorLightBlue = 16777088; colorOrange = 33023; colorGrey = 8421504; colorSilver = 12632256; colorPink = 16744703; colorWhite = 16777215; colorDarkGrey = 128; colorBlack = 0; colorRed = 255; colorLightRed = 8421631; colorDarkPerp = 11534424;
type
TRanges = record CurrRow:integer; CurrSheet:integer; EndRow:Char; {по умолчанию B} EndRowGlb:Char; {glb row default B} MergeEnd:Char; {по умолчанию B} ColumnWidths: array ['A'..'Z'] of real; {Работает, если задан EndRow} BeckgroundColor:integer; {Работает, если задан EndRow} Formats: array [1..10] of string; {NumberFormat: ### ### ##0.00} LineStyle:integer; {Table linestyle Default = 1} Formula:string; end;
cExcel = class public WKB, Exc : OleVariant; Template : string; Ranges : TRanges; //procedure SetBeckgroungColorA(col:integer);{автоматически} procedure DrawTableA(S:Char); procedure DrawTableM(S1,S2:Char); procedure MergeA(S:Char); procedure MergeM(S1,S2:Char); procedure DrawColorA(S:Char; col:integer); procedure DrawColorM(S1,S2:Char; col:integer); procedure StartExcel(ChangeColWidths:boolean); constructor Create; procedure SetVisible(const AValue: boolean); function GetVisible: boolean; procedure SetRangeVal(const S:Char; const AValue:string); function GetRangeVal(const S:Char): string; function Range(S:Char): OleVariant; property Visible : boolean read GetVisible write SetVisible; private procedure SetColWidths; end;
implementation
uses ComObj, Variants, VarUtils, Classes, SysUtils, ExcelXP, Dialogs, DateUtils;
constructor cExcel.Create; var i:integer; begin Exc := null; Template := ''; with Ranges do begin CurrRow:=1; CurrSheet:=1; EndRow:='B'; EndRowGlb:='B'; MergeEnd:='B'; for i:=ord('A') to ord('Z') do ColumnWidths[chr(i)]:=8.43; BeckgroundColor:=0; for i:=1 to 10 do Formats[i]:='#'; LineStyle:=1; Formula:=''; end; end;
procedure cExcel.DrawColorA(S:Char; col:integer); begin WKB.Range[S + IntToStr(Ranges.CurrRow), Ranges.EndRowGlb + IntToStr(Ranges.CurrRow)].Interior.Color:=col; end;
procedure cExcel.DrawColorM(S1,S2:Char; col:integer); begin WKB.Range[S1 + IntToStr(Ranges.CurrRow), S2 + IntToStr(Ranges.CurrRow)].Interior.Color:=col; end;
procedure cExcel.SetColWidths; var i:integer; begin for i:=ord('A') to ord(Ranges.EndRowGlb) do Range(chr(i)).ColumnWidth:=Ranges.ColumnWidths[chr(i)]; end;
function cExcel.Range(S:Char): OleVariant; begin Result:=WKB.Range[S + IntToStr(Ranges.CurrRow)]; end;
procedure cExcel.SetRangeVal(const S:Char; const AValue:string); begin Range(S).Value:=AValue; end;
function cExcel.GetRangeVal(const S:Char): string; begin result:=Range(S).Value end;
procedure cExcel.DrawTableA(S:Char); begin WKB.Range[S + IntToStr(Ranges.CurrRow), Ranges.EndRowGlb + IntToStr(Ranges.CurrRow)].Borders.Linestyle:=Ranges.LineStyle; end;
procedure cExcel.DrawTableM(S1,S2:Char); begin WKB.Range[S1 + IntToStr(Ranges.CurrRow), S2 + IntToStr(Ranges.CurrRow)].Borders.Linestyle:=Ranges.LineStyle; end;
procedure cExcel.MergeA(S:Char); begin WKB.Range[S + IntToStr(Ranges.CurrRow), Ranges.MergeEnd + IntToStr(Ranges.CurrRow)].Merge; end;
procedure cExcel.MergeM(S1,S2:Char); begin WKB.Range[S1 + IntToStr(Ranges.CurrRow), S2 + IntToStr(Ranges.CurrRow)].Merge; end;
{ procedure cExcel.SetBeckgroungColorA(col:integer); begin WKB.Range['A', Ranges.EndRow].Interior.Color:=col; end; }
procedure cExcel.SetVisible(const AValue: boolean); begin if Exc.Visible <> AValue then Exc.Visible := Variant(AValue); end;
function cExcel.GetVisible: boolean; begin Result := Exc.Visible or false; end;
procedure cExcel.StartExcel(ChangeColWidths:boolean); begin Exc := CreateOleObject('Excel.Application'); if (Template<>'') and (FileExists(Template)) then Exc.Workbooks.Open(Template);
if ChangeColWidths=true then SetColWidths;
WKB:=Exc.ActiveWorkbook; end;
end.
|
тело программы: Код | var cE:cExcel;
procedure TTestForm.SetExcParams; begin cE.Ranges.EndRow:='F'; cE.Ranges.EndRowGlb:='H'; cE.Ranges.MergeEnd:='F'; cE.Ranges.ColumnWidths['A']:=7.71; cE.Ranges.ColumnWidths['B']:=8.29; cE.Ranges.ColumnWidths['C']:=9.57; cE.Ranges.ColumnWidths['D']:=8.71; cE.Ranges.ColumnWidths['E']:=8.43; cE.Ranges.ColumnWidths['F']:=3.57; cE.Ranges.ColumnWidths['G']:=12.00; cE.Ranges.ColumnWidths['H']:=12.00; cE.Template:='template(test).xls'; end;
procedure TTestForm.Button1Click(Sender: TObject); begin SetExcParams; cE.StartExcel(true); cE.Visible:=true; end;
|
--------------------
I want a perfect soul
|