frx2xto30.pas
上传用户:cldfzq
上传日期:2008-05-27
资源大小:2956k
文件大小:71k
- {******************************************}
- { }
- { FastReport v3.0 }
- { FR2.x importer }
- { }
- { Copyright (c) 1998-2005 }
- { by Alexander Tzyganenko, }
- { Fast Reports Inc. }
- { }
- {******************************************}
- unit frx2xto30;
- interface
- {$I frx.inc}
- implementation
- uses
- SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls, Printers, TypInfo, Jpeg, DB,
- frxClass, frxVariables, frxPrinter, frxDCtrl, frxBarcode, frxBarcod,
- TeeProcs, TeEngine, Chart, Series, frxChart, frxChBox, frxOLE, frxRich,
- frxCross, frxCrossMatrix, frxDBSet, frxUnicodeUtils, frxUtils, fs_ipascal,
- frxCustomDB, frxBDEComponents, frxADOComponents, frxIBXComponents
- {$IFDEF Delphi6}
- , Variants
- {$ENDIF};
- type
- TfrxFR2EventsNew = class(TObject)
- private
- FReport: TfrxReport;
- procedure DoGetValue(const Expr: String; var Value: Variant);
- procedure DoPrepareScript(Sender: TObject);
- function GetScriptValue(Instance: TObject; ClassType: TClass;
- const MethodName: String; var Params: Variant): Variant;
- function DoLoad(Sender: TfrxReport; Stream: TStream): Boolean;
- function DoGetScriptValue(var Params: Variant): Variant;
- end;
- TfrPageType = (ptReport, ptDialog);
- TfrBandType = (btReportTitle, btReportSummary,
- btPageHeader, btPageFooter,
- btMasterHeader, btMasterData, btMasterFooter,
- btDetailHeader, btDetailData, btDetailFooter,
- btSubDetailHeader, btSubDetailData, btSubDetailFooter,
- btOverlay, btColumnHeader, btColumnFooter,
- btGroupHeader, btGroupFooter,
- btCrossHeader, btCrossData, btCrossFooter,
- btChild, btNone);
- TfrxFixupItem = class(TObject)
- public
- Obj: TPersistent;
- PropInfo: PPropInfo;
- Value: String;
- end;
- TfrHighlightAttr = packed record
- FontStyle: Word;
- FontColor, FillColor: TColor;
- end;
- TfrBarCodeRec = packed record
- cCheckSum : Boolean;
- cShowText : Boolean;
- cCadr : Boolean;
- cBarType : TfrxBarcodeType;
- cModul : Integer;
- cRatio : Double;
- cAngle : Double;
- end;
- TChartOptions = packed record
- ChartType: Byte;
- Dim3D, IsSingle, ShowLegend, ShowAxis, ShowMarks, Colored: Boolean;
- MarksStyle: Byte;
- Top10Num: Integer;
- Reserved: array[0..35] of Byte;
- end;
- TfrRoundRect = packed record
- SdColor: TColor; // Color of Shadow
- wShadow: Integer; // Width of shadow
- Cadre : Boolean; // Frame On/Off - not used /TZ/
- sCurve : Boolean; // RoundRect On/Off
- wCurve : Integer; // Curve size
- end;
- THackControl = class(TControl)
- end;
- TSeriesClass = class of TChartSeries;
- const
- gtMemo = 0;
- gtPicture = 1;
- gtBand = 2;
- gtSubReport = 3;
- gtLine = 4;
- gtCross = 5;
- gtAddIn = 10;
- frftNone = 0;
- frftRight = 1;
- frftBottom = 2;
- frftLeft = 4;
- frftTop = 8;
- frtaLeft = 0;
- frtaRight = 1;
- frtaCenter = 2;
- frtaVertical = 4;
- frtaMiddle = 8;
- frtaDown = 16;
- flStretched = 1;
- flWordWrap = 2;
- flWordBreak = 4;
- flAutoSize = 8;
- flTextOnly = $10;
- flSuppressRepeated = $20;
- flHideZeros = $40;
- flUnderlines = $80;
- flRTLReading = $100;
- flBandNewPageAfter = 2;
- flBandPrintifSubsetEmpty = 4;
- flBandBreaked = 8;
- flBandOnFirstPage = $10;
- flBandOnLastPage = $20;
- flBandRepeatHeader = $40;
- flBandPrintChildIfInvisible = $80;
- flPictCenter = 2;
- flPictRatio = 4;
- flWantHook = $8000;
- flDontUndo = $4000;
- flOnePerPage = $2000;
- pkNone = 0;
- pkBitmap = 1;
- pkMetafile = 2;
- pkIcon = 3;
- pkJPEG = 4;
- var
- frVersion: Byte;
- Report: TfrxReport;
- Stream: TStream;
- Page: TfrxPage;
- Fixups: TList;
- offsx, offsy: Integer;
- frxFR2EventsNew: TfrxFR2EventsNew;
- const
- frSpecCount = 9;
- frSpecFuncs: array[0..frSpecCount - 1] of String =
- ('PAGE#', '', 'DATE', 'TIME', 'LINE#', 'LINETHROUGH#', 'COLUMN#',
- 'CURRENT#', 'TOTALPAGES');
- Bands: array[TfrBandType] of TfrxBandClass =
- (TfrxReportTitle, TfrxReportSummary,
- TfrxPageHeader, TfrxPageFooter,
- TfrxHeader, TfrxMasterData, TfrxFooter,
- TfrxHeader, TfrxDetailData, TfrxFooter,
- TfrxHeader, TfrxSubDetailData, TfrxFooter,
- TfrxOverlay, TfrxColumnHeader, TfrxColumnFooter,
- TfrxGroupHeader, TfrxGroupFooter,
- TfrxHeader, TfrxMasterData, TfrxFooter,
- TfrxChild, nil);
- cbDefaultText = '12345678';
- ChartTypes: array[0..5] of TSeriesClass =
- (TLineSeries, TAreaSeries, TPointSeries,
- TBarSeries, THorizBarSeries, TPieSeries);
- frRepInfoCount = 9;
- frRepInfo: array[0..frRepInfoCount-1] of String =
- ('REPORTCOMMENT', 'REPORTNAME', 'REPORTAUTOR',
- 'VMAJOR', 'VMINOR', 'VRELEASE', 'VBUILD', 'REPORTDATE', 'REPORTLASTCHANGE');
- ParamTypes: array[0..10] of TFieldType =
- (ftBCD, ftBoolean, ftCurrency, ftDate, ftDateTime, ftInteger,
- ftFloat, ftSmallint, ftString, ftTime, ftWord);
- procedure frGetDataSetAndField(ComplexName: String; var DataSet: TDataSet;
- var Field: String); forward;
- function frGetFieldValue(F: TField): Variant; forward;
- procedure LoadFromFR2Stream(AReport: TfrxReport; AStream: TStream); forward;
- function ConvertDatasetAndField(s: String): String; forward;
- { ------------------ hack FR events --------------------------------------- }
- { TfrxFR2EventsNew }
- procedure TfrxFR2EventsNew.DoGetValue(const Expr: String; var Value: Variant);
- var
- Dataset: TDataset;
- s, Field: String;
- tf: TField;
- ds: TfrxDataSet;
- fld: String;
- begin
- Dataset := nil;
- Field := '';
- if CompareText(Expr, 'COLUMN#') = 0 then
- Value := Report.Engine.CurLine
- else
- begin
- s := Expr;
- if Pos('DialogForm.', s) = 1 then
- begin
- Delete(s, 1, Length('DialogForm.'));
- Report.GetDataSetAndField(s, ds, fld);
- if (ds <> nil) and (fld <> '') then
- begin
- Value := ds.Value[fld];
- if Report.EngineOptions.ConvertNulls and (Value = Null) then
- case ds.FieldType[fld] of
- fftNumeric:
- Value := 0;
- fftString:
- Value := '';
- fftBoolean:
- Value := False;
- end;
- Exit;
- end;
- end;
- frGetDataSetAndField(s, Dataset, Field);
- if (Dataset <> nil) and (Field <> '') then
- begin
- tf := Dataset.FieldByName(Field);
- Value := frGetFieldValue(tf);
- end;
- end;
- end;
- procedure TfrxFR2EventsNew.DoPrepareScript(Sender: TObject);
- var
- i: Integer;
- begin
- FReport := TfrxReport(Sender);
- Report := FReport;
- for i := 0 to FReport.Variables.Count - 1 do
- if IsValidIdent(FReport.Variables.Items[i].Name) then
- FReport.Script.AddMethod('function ' + FReport.Variables.Items[i].Name + ': Variant', GetScriptValue);
- end;
- function TfrxFR2EventsNew.GetScriptValue(Instance: TObject;
- ClassType: TClass; const MethodName: String;
- var Params: Variant): Variant;
- var
- i: Integer;
- val: Variant;
- begin
- i := FReport.Variables.IndexOf(MethodName);
- if i <> -1 then
- begin
- val := FReport.Variables.Items[i].Value;
- if (TVarData(val).VType = varString) or (TVarData(val).VType = varOleStr) then
- begin
- if Pos(#13#10, val) <> 0 then
- Result := val
- else
- Result := FReport.Calc(val);
- end
- else
- Result := val;
- end;
- end;
- function TfrxFR2EventsNew.DoLoad(Sender: TfrxReport; Stream: TStream): Boolean;
- begin
- Result := False;
- Stream.Read(frVersion, 1);
- Stream.Seek(-1, soFromCurrent);
- if frVersion < 30 then
- begin
- LoadFromFR2Stream(Sender, Stream);
- Result := True;
- end;
- end;
- function TfrxFR2EventsNew.DoGetScriptValue(var Params: Variant): Variant;
- begin
- Result := FReport.Calc('`' + Params[0] + '`', FReport.Script.ProgRunning);
- end;
- { ------------------ fixups ----------------------------------------------- }
- procedure ClearFixups;
- begin
- while Fixups.Count > 0 do
- begin
- TfrxFixupItem(Fixups[0]).Free;
- Fixups.Delete(0);
- end;
- end;
- procedure FixupReferences;
- var
- i: Integer;
- Item: TfrxFixupItem;
- Ref: TObject;
- begin
- for i := 0 to Fixups.Count - 1 do
- begin
- Item := Fixups[i];
- Ref := Report.FindObject(Item.Value);
- if Ref <> nil then
- SetOrdProp(Item.Obj, Item.PropInfo, Integer(Ref));
- end;
- ClearFixups;
- end;
- procedure AddFixup(Obj: TPersistent; Name, Value: String);
- var
- Item: TfrxFixupItem;
- begin
- Item := TfrxFixupItem.Create;
- Item.Obj := Obj;
- Item.PropInfo := GetPropInfo(Obj.ClassInfo, Name);
- Item.Value := Value;
- Fixups.Add(Item);
- end;
- { ------------------ stream readers -------------------------------------- }
- function frSetFontStyle(Style: Integer): TFontStyles;
- begin
- Result := [];
- if (Style and $1) <> 0 then Result := Result + [fsItalic];
- if (Style and $2) <> 0 then Result := Result + [fsBold];
- if (Style and $4) <> 0 then Result := Result + [fsUnderLine];
- if (Style and $8) <> 0 then Result := Result + [fsStrikeOut];
- end;
- procedure frReadMemo(Stream: TStream; l: TStrings);
- var
- s: String;
- b: Byte;
- n: Word;
- begin
- l.Clear;
- Stream.Read(n, 2);
- if n > 0 then
- repeat
- Stream.Read(n, 2);
- SetLength(s, n);
- if n > 0 then
- Stream.Read(s[1], n);
- l.Add(s);
- Stream.Read(b, 1);
- until b = 0
- else
- Stream.Read(b, 1);
- end;
- function frReadString(Stream: TStream): String;
- var
- s: String;
- n: Word;
- b: Byte;
- begin
- Stream.Read(n, 2);
- SetLength(s, n);
- if n > 0 then
- Stream.Read(s[1], n);
- Stream.Read(b, 1);
- Result := s;
- end;
- procedure frReadMemo22(Stream: TStream; l: TStrings);
- var
- s: String;
- i: Integer;
- b: Byte;
- begin
- SetLength(s, 4096);
- l.Clear;
- i := 1;
- repeat
- Stream.Read(b,1);
- if (b = 13) or (b = 0) then
- begin
- SetLength(s, i - 1);
- if not ((b = 0) and (i = 1)) then l.Add(s);
- SetLength(s, 4096);
- i := 1;
- end
- else if b <> 0 then
- begin
- s[i] := Chr(b);
- Inc(i);
- if i > 4096 then
- SetLength(s, Length(s) + 4096);
- end;
- until b = 0;
- end;
- function frReadString22(Stream: TStream): String;
- var
- s: String;
- i: Integer;
- b: Byte;
- begin
- SetLength(s, 4096);
- i := 1;
- repeat
- Stream.Read(b, 1);
- if b = 0 then
- SetLength(s, i - 1)
- else
- begin
- s[i] := Chr(b);
- Inc(i);
- if i > 4096 then
- SetLength(s, Length(s) + 4096);
- end;
- until b = 0;
- Result := s;
- end;
- function frReadBoolean(Stream: TStream): Boolean;
- begin
- Stream.Read(Result, 1);
- end;
- function frReadByte(Stream: TStream): Byte;
- begin
- Stream.Read(Result, 1);
- end;
- function frReadWord(Stream: TStream): Word;
- begin
- Stream.Read(Result, 2);
- end;
- function frReadInteger(Stream: TStream): Integer;
- begin
- Stream.Read(Result, 4);
- end;
- procedure frReadFont(Stream: TStream; Font: TFont);
- var
- w: Word;
- begin
- Font.Name := frReadString(Stream);
- Font.Size := frReadInteger(Stream);
- Font.Style := frSetFontStyle(frReadWord(Stream));
- Font.Color := frReadInteger(Stream);
- w := frReadWord(Stream);
- Font.Charset := w;
- end;
- function ReadString(Stream: TStream): String;
- begin
- if frVersion >= 23 then
- Result := frReadString(Stream) else
- Result := frReadString22(Stream);
- end;
- procedure ReadMemo(Stream: TStream; Memo: TStrings);
- begin
- if frVersion >= 23 then
- frReadMemo(Stream, Memo) else
- frReadMemo22(Stream, Memo);
- end;
- { --------------------------- utils -------------------------------- }
- function frFindComponent(Owner: TComponent; Name: String): TComponent;
- var
- n: Integer;
- s1, s2: String;
- begin
- Result := nil;
- n := Pos('.', Name);
- try
- if n = 0 then
- Result := Owner.FindComponent(Name)
- else
- begin
- s1 := Copy(Name, 1, n - 1); // module name
- s2 := Copy(Name, n + 1, 255); // component name
- Owner := FindGlobalComponent(s1);
- if Owner <> nil then
- begin
- n := Pos('.', s2);
- if n <> 0 then // frame name - Delphi5
- begin
- s1 := Copy(s2, 1, n - 1);
- s2 := Copy(s2, n + 1, 255);
- Owner := Owner.FindComponent(s1);
- if Owner <> nil then
- Result := Owner.FindComponent(s2);
- end
- else
- Result := Owner.FindComponent(s2);
- end;
- end;
- except
- on Exception do
- raise EClassNotFound.Create('Missing ' + Name);
- end;
- end;
- function frRemoveQuotes(const s: String): String;
- begin
- if (Length(s) > 2) and (s[1] = '"') and (s[Length(s)] = '"') then
- Result := Copy(s, 2, Length(s) - 2) else
- Result := s;
- end;
- function frRemoveQuotes1(const s: String): String;
- begin
- if (Length(s) > 2) and (s[1] = '''') and (s[Length(s)] = '''') then
- Result := Copy(s, 2, Length(s) - 2) else
- Result := s;
- end;
- procedure frGetFieldNames(DataSet: TDataSet; List: TStrings);
- begin
- try
- DataSet.GetFieldNames(List);
- except;
- end;
- end;
- procedure frGetDataSetAndField(ComplexName: String; var DataSet: TDataSet;
- var Field: String);
- var
- i, j, n: Integer;
- f: TComponent;
- sl: TStringList;
- s: String;
- c: Char;
- cn: TControl;
- function FindField(ds: TDataSet; FName: String): String;
- var
- sl: TStringList;
- begin
- Result := '';
- if ds <> nil then
- begin
- sl := TStringList.Create;
- frGetFieldNames(ds, sl);
- if sl.IndexOf(FName) <> -1 then
- Result := FName;
- sl.Free;
- end;
- end;
- begin
- Field := '';
- f := Report.Owner;
- sl := TStringList.Create;
- n := 0; j := 1;
- for i := 1 to Length(ComplexName) do
- begin
- c := ComplexName[i];
- if c = '"' then
- begin
- sl.Add(Copy(ComplexName, i, 255));
- j := i;
- break;
- end
- else if c = '.' then
- begin
- sl.Add(Copy(ComplexName, j, i - j));
- j := i + 1;
- Inc(n);
- end;
- end;
- if j <> i then
- sl.Add(Copy(ComplexName, j, 255));
- case n of
- 0: // field name only
- begin
- if DataSet <> nil then
- begin
- s := frRemoveQuotes(ComplexName);
- Field := FindField(DataSet, s);
- end;
- end;
- 1: // DatasetName.FieldName
- begin
- if sl.Count > 1 then
- begin
- DataSet := TDataSet(frFindComponent(f, sl[0]));
- s := frRemoveQuotes(sl[1]);
- Field := FindField(DataSet, s);
- end;
- end;
- 2: // FormName.DatasetName.FieldName
- begin
- f := FindGlobalComponent(sl[0]);
- if f <> nil then
- begin
- DataSet := TDataSet(f.FindComponent(sl[1]));
- s := frRemoveQuotes(sl[2]);
- Field := FindField(DataSet, s);
- end;
- end;
- 3: // FormName.FrameName.DatasetName.FieldName - Delphi5
- begin
- f := FindGlobalComponent(sl[0]);
- if f <> nil then
- begin
- cn := TControl(f.FindComponent(sl[1]));
- DataSet := TDataSet(cn.FindComponent(sl[2]));
- s := frRemoveQuotes(sl[3]);
- Field := FindField(DataSet, s);
- end;
- end;
- end;
- sl.Free;
- end;
- function frGetFieldValue(F: TField): Variant;
- begin
- if not F.DataSet.Active then
- F.DataSet.Open;
- if Assigned(F.OnGetText) then
- Result := F.DisplayText
- else if F.DataType in [ftLargeint] then
- Result := F.DisplayText
- else
- Result := F.AsVariant;
- if Result = Null then
- if F.DataType = ftString then
- Result := ''
- else if F.DataType = ftWideString then
- Result := ''
- else if F.DataType = ftBoolean then
- Result := False
- else
- Result := 0;
- end;
- function FindTfrxDataset(ds: TDataset): TfrxDataset;
- var
- i: Integer;
- sl: TStringList;
- ds1: TfrxDataset;
- begin
- Result := nil;
- sl := TStringList.Create;
- frxGetDatasetList(sl);
- for i := 0 to sl.Count - 1 do
- begin
- ds1 := TfrxDataset(sl.Objects[i]);
- if (ds1 is TfrxDBDataset) and (TfrxDBDataset(ds1).GetDataSet = ds) then
- begin
- Result := ds1;
- break;
- end;
- end;
- sl.Free;
- end;
- function GetBrackedVariable(const s: String; var i, j: Integer): String;
- var
- c: Integer;
- fl1, fl2: Boolean;
- begin
- j := i; fl1 := True; fl2 := True; c := 0;
- Result := '';
- if (s = '') or (j > Length(s)) then Exit;
- Dec(j);
- repeat
- Inc(j);
- if fl1 and fl2 then
- if s[j] = '[' then
- begin
- if c = 0 then i := j;
- Inc(c);
- end
- else if s[j] = ']' then Dec(c);
- if fl1 then
- if s[j] = '"' then fl2 := not fl2;
- if fl2 then
- if s[j] = '''' then fl1 := not fl1;
- until (c = 0) or (j >= Length(s));
- Result := Copy(s, i + 1, j - i - 1);
- end;
- function Substitute(const ParName: String): String;
- begin
- Result := ParName;
- if CompareText(ParName, frRepInfo[0]) = 0 then
- Result := 'Report.ReportOptions.Description'
- else if CompareText(ParName, frRepInfo[1]) = 0 then
- Result := 'Report.ReportOptions.Name'
- else if CompareText(ParName, frRepInfo[2]) = 0 then
- Result := 'Report.ReportOptions.Author'
- else if CompareText(ParName, frRepInfo[3]) = 0 then
- Result := 'Report.ReportOptions.VersionMajor'
- else if CompareText(ParName, frRepInfo[4]) = 0 then
- Result := 'Report.ReportOptions.VersionMinor'
- else if CompareText(ParName, frRepInfo[5]) = 0 then
- Result := 'Report.ReportOptions.VersionRelease'
- else if CompareText(ParName, frRepInfo[6]) = 0 then
- Result := 'Report.ReportOptions.VersionBuild'
- else if CompareText(ParName, frRepInfo[7]) = 0 then
- Result := 'Report.ReportOptions.CreateDate'
- else if CompareText(ParName, frRepInfo[8]) = 0 then
- Result := 'Report.ReportOptions.LastChange'
- else if CompareText(ParName, 'CURY') = 0 then
- Result := 'Engine.CurY'
- else if CompareText(ParName, 'FREESPACE') = 0 then
- Result := 'Engine.FreeSpace'
- else if CompareText(ParName, 'FINALPASS') = 0 then
- Result := 'Engine.FinalPass'
- else if CompareText(ParName, 'PAGEHEIGHT') = 0 then
- Result := 'Engine.PageHeight'
- else if CompareText(ParName, 'PAGEWIDTH') = 0 then
- Result := 'Engine.PageWidth'
- end;
- procedure DoExpression(const Expr: String; var Value: String);
- begin
- Value := Substitute(Expr);
- if ConvertDatasetAndField(Expr) <> Expr then
- Value := ConvertDatasetAndField(Expr);
- end;
- procedure ExpandVariables(var s: String);
- var
- i, j: Integer;
- s1, s2: String;
- begin
- i := 1;
- repeat
- while (i < Length(s)) and (s[i] <> '[') do Inc(i);
- s1 := GetBrackedVariable(s, i, j);
- if i <> j then
- begin
- Delete(s, i, j - i + 1);
- s2 := s1;
- DoExpression(s1, s2);
- s2 := '[' + s2 + ']';
- Insert(s2, s, i);
- Inc(i, Length(s2));
- j := 0;
- end;
- until i = j;
- end;
- procedure ExpandVariables1(var s: String);
- var
- i, j: Integer;
- s1, s2: String;
- begin
- i := 1;
- repeat
- while (i < Length(s)) and (s[i] <> '[') do Inc(i);
- s1 := GetBrackedVariable(s, i, j);
- if i <> j then
- begin
- Delete(s, i, j - i + 1);
- s2 := s1;
- DoExpression(s1, s2);
- Insert(s2, s, i);
- Inc(i, Length(s2));
- j := 0;
- end;
- until i = j;
- end;
- procedure ConvertMemoExpressions(m: TfrxCustomMemoView; s: String);
- begin
- ExpandVariables(s);
- m.Memo.Text := AnsiToUnicode(s, m.Font.Charset);
- end;
- { --------------------------- report items -------------------------------- }
- var
- Name: String;
- HVersion, LVersion: Byte;
- x, y, dx, dy: Integer;
- Flags: Word;
- FrameTyp: Word;
- FrameWidth: Single;
- FrameColor: TColor;
- FrameStyle: Word;
- FillColor: TColor;
- Format: Integer;
- FormatStr: String;
- Visible: WordBool;
- gapx, gapy: Integer;
- Restrictions: Word;
- Tag: String;
- Memo, Script: TStringList;
- BandAlign: Byte;
- NeedCreateName: Boolean;
- procedure AddScript(c: TfrxComponent; const ScriptName: String);
- var
- i: Integer;
- vName: String;
- begin
- vName := c.Name;
- if Script.Count <> 0 then
- begin
- Report.ScriptText.Add('procedure ' + vName + scriptName);
- Report.ScriptText.Add('begin');
- Report.ScriptText.Add(' with ' + vName + ', Engine do');
- Report.ScriptText.Add(' begin');
- if Script[0] <> 'begin' then
- Report.ScriptText.Add(Script[0]);
- for i := 1 to Script.Count - 2 do
- Report.ScriptText.Add(Script[i]);
- if Script[0] <> 'begin' then
- begin
- if Script.Count <> 1 then
- Report.ScriptText.Add(Script[Script.Count - 1]);
- Report.ScriptText.Add(' end');
- Report.ScriptText.Add('end;');
- end
- else
- begin
- Report.ScriptText.Add(' end');
- Report.ScriptText.Add(Script[Script.Count - 1] + ';');
- end;
- Report.ScriptText.Add('');
- if c is TfrxDialogPage then
- TfrxDialogPage(c).OnShow := vName + 'OnShow'
- else if c is TfrxDialogControl then
- TfrxDialogControl(c).OnClick := vName + 'OnClick'
- else if c is TfrxReportComponent then
- TfrxReportComponent(c).OnBeforePrint := vName + 'OnBeforePrint';
- end;
- end;
- procedure SetfrxComponent(c: TfrxComponent);
- procedure SetValidIdent(var Ident: string);
- const
- Alpha = ['A'..'Z', 'a'..'z', '_'];
- AlphaNumeric = Alpha + ['0'..'9'];
- var
- I: Integer;
- begin
- if (Length(Ident) > 0) and not (Ident[1] in Alpha) then
- Ident[1] := '_';
- for I := 2 to Length(Ident) do
- if not (Ident[I] in AlphaNumeric) then
- Ident[I] := '_';
- end;
- begin
- SetValidIdent(Name);
- c.Name := Name;
- if NeedCreateName then
- c.CreateUniqueName;
- c.Left := x + offsx;
- c.Top := y + offsy;
- c.Width := dx;
- c.Height := dy;
- c.Visible := Visible;
- end;
- procedure SetfrxView(c: TfrxView);
- begin
- if (FrameTyp and frftRight) <> 0 then
- c.Frame.Typ := c.Frame.Typ + [ftRight];
- if (FrameTyp and frftBottom) <> 0 then
- c.Frame.Typ := c.Frame.Typ + [ftBottom];
- if (FrameTyp and frftLeft) <> 0 then
- c.Frame.Typ := c.Frame.Typ + [ftLeft];
- if (FrameTyp and frftTop) <> 0 then
- c.Frame.Typ := c.Frame.Typ + [ftTop];
- c.Frame.Width := FrameWidth;
- c.Frame.Color := FrameColor;
- c.Frame.Style := TfrxFrameStyle(FrameStyle);
- c.Color := FillColor;
- c.Align := TfrxAlign(BandAlign);
- c.TagStr := Tag;
- AddScript(c, 'OnBeforePrint(Sender: TfrxComponent);');
- end;
- procedure TfrViewLoadFromStream;
- var
- w: Integer;
- begin
- with Stream do
- begin
- NeedCreateName := False;
- if frVersion >= 23 then
- Name := ReadString(Stream) else
- NeedCreateName := True;
- if frVersion > 23 then
- begin
- Read(HVersion, 1);
- Read(LVersion, 1);
- end;
- Read(x, 4); Read(y, 4); Read(dx, 4); Read(dy, 4);
- Read(Flags, 2); Read(FrameTyp, 2); Read(FrameWidth, 4);
- Read(FrameColor, 4); Read(FrameStyle, 2);
- Read(FillColor, 4);
- Read(Format, 4);
- FormatStr := ReadString(Stream);
- ReadMemo(Stream, Memo);
- if frVersion >= 23 then
- begin
- ReadMemo(Stream, Script);
- Read(Visible, 2);
- end;
- if frVersion >= 24 then
- begin
- Read(Restrictions, 2);
- Tag := ReadString(Stream);
- Read(gapx, 4);
- Read(gapy, 4);
- end;
- w := PInteger(@FrameWidth)^;
- if w <= 10 then
- w := w * 1000;
- if HVersion > 1 then
- Read(BandAlign, 1);
- FrameWidth := w / 1000;
- end;
- end;
- procedure TfrMemoViewLoadFromStream;
- var
- w: Word;
- i: Integer;
- Alignment: Integer;
- Highlight: TfrHighlightAttr;
- HighlightStr: String;
- LineSpacing, CharacterSpacing: Integer;
- m: TfrxMemoView;
- procedure DecodeDisplayFormat;
- var
- LCategory: Byte;
- LType: Byte;
- LNoOfDecimals: Byte;
- LSeparator: Char;
- begin
- LCategory := (Format and $0F000000) shr 24;
- LType := (Format and $00FF0000) shr 16;
- LNoOfDecimals := (Format and $0000FF00) shr 8;
- LSeparator := Chr(Format and $000000FF);
- case LCategory of
- 0: { text }
- m.DisplayFormat.Kind := fkText;
- 1: { number }
- begin
- m.DisplayFormat.Kind := fkNumeric;
- m.DisplayFormat.DecimalSeparator := LSeparator;
- case LType of
- 0: m.DisplayFormat.FormatStr := '%2.' + IntToStr(LNoOfDecimals) + 'g';
- 1: m.DisplayFormat.FormatStr := '%g';
- 2: m.DisplayFormat.FormatStr := '%2.' + IntToStr(LNoOfDecimals) + 'f';
- 3: m.DisplayFormat.FormatStr := '%2.' + IntToStr(LNoOfDecimals) + 'n';
- else
- m.DisplayFormat.FormatStr := '%g' { can't convert custom format string };
- end;
- end;
- 2: { date }
- begin
- m.DisplayFormat.Kind := fkDateTime;
- case LType of
- 0: m.DisplayFormat.FormatStr := 'dd.mm.yy';
- 1: m.DisplayFormat.FormatStr := 'dd.mm.yyyy';
- 2: m.DisplayFormat.FormatStr := 'd mmm yyyy';
- 3: m.DisplayFormat.FormatStr := LongDateFormat;
- 4: m.DisplayFormat.FormatStr := FormatStr;
- end;
- end;
- 3: { time }
- begin
- m.DisplayFormat.Kind := fkDateTime;
- case LType of
- 0: m.DisplayFormat.FormatStr := 'hh:nn:ss';
- 1: m.DisplayFormat.FormatStr := 'h:nn:ss';
- 2: m.DisplayFormat.FormatStr := 'hh:nn';
- 3: m.DisplayFormat.FormatStr := 'h:nn';
- 4: m.DisplayFormat.FormatStr := FormatStr;
- end;
- end;
- 4: { boolean }
- begin
- m.DisplayFormat.Kind := fkBoolean;
- case LType of
- 0: m.DisplayFormat.FormatStr := '0,1';
- 1: m.DisplayFormat.FormatStr := '崶