diff --git a/designer/designer.pp b/designer/designer.pp index b0d385c78a..5597afb9ae 100644 --- a/designer/designer.pp +++ b/designer/designer.pp @@ -70,14 +70,6 @@ uses var GridPoints : TGridPoint; -Function TDesigner.GetFormAncestor : String; -var - PI : PTypeInfo; -begin - PI := FCustomForm.ClassInfo; - Result := PI^.Name; - Delete(Result,1,1); -end; constructor TDesigner.Create(CustomForm : TCustomForm); var @@ -120,6 +112,16 @@ Begin Inherited; end; +Function TDesigner.GetFormAncestor : String; +var + PI : PTypeInfo; +begin + PI := FCustomForm.ClassInfo; + Result := PI^.Name; + Delete(Result,1,1); +end; + + procedure TDesigner.CreateNew(FileName : string); begin @@ -215,13 +217,11 @@ For I := 0 to FSource.Count-1 do end; - procedure TDesigner.Notification(AComponent: TComponent; Operation: TOperation); Begin - if Operation = opInsert then - Begin -// AddControlCode(AComponent); - end + if Operation = opInsert then + begin + end else if Operation = opRemove then begin diff --git a/designer/test_unit.pp b/designer/test_unit.pp index 34026d7e14..b79398f1f7 100644 --- a/designer/test_unit.pp +++ b/designer/test_unit.pp @@ -78,19 +78,16 @@ type OIResizeButton: TButton; OIRefreshButton: TButton; Edit1 : TEdit; - mnuMain: TMainMenu; - itmFileQuit: TMenuItem; - itmFile: TMenuItem; ComboBox1 : TComboBox; ComboBox2 : TComboBox; Memo1 : TMemo; WriteLFMButton:TButton; - constructor Create(AOwner: TComponent); override; + constructor Create(AOwner: TComponent); override; procedure LoadMainMenu; + procedure LoadFromLFM; + published procedure FormKill(Sender : TObject); procedure FormShow(Sender : TObject); - procedure mnuQuitClicked(Sender : TObject); - protected procedure EditToComboButtonCLick(Sender : TObject); procedure AddItemButtonCLick(Sender : TObject); procedure ComboToEditButtonCLick(Sender : TObject); @@ -102,7 +99,22 @@ type procedure ComboOnChange (Sender:TObject); procedure ComboOnClick (Sender:TObject); procedure WriteLFMButtonClick(Sender:TObject); + private + procedure ReaderFindMethod(Reader: TReader; const FindMethodName: Ansistring; + var Address: Pointer; var Error: Boolean); + procedure ReaderSetName(Reader: TReader; Component: TComponent; + var NewName: Ansistring); + procedure ReaderReferenceName(Reader: TReader; var RefName: Ansistring); + procedure ReaderAncestorNotFound(Reader: TReader; const ComponentName: Ansistring; + ComponentClass: TPersistentClass; var Component: TComponent); + procedure ReaderError(Reader: TReader; const Message: Ansistring; + var Handled: Boolean); + procedure ReaderFindComponentClass(Reader: TReader; const FindClassName: Ansistring; + var ComponentClass: TComponentClass); + procedure ReaderCreateComponent(Reader: TReader; + ComponentClass: TComponentClass; var Component: TComponent); public + // some test variables FMyInteger:integer; FMyCardinal:Cardinal; FMyEnum:TMyEnum; @@ -114,6 +126,7 @@ type FMyPen:TPen; FMyFont:TFont; FMyComponent:TMyComponent; + FMyEvent:TNotifyEvent; procedure SetMyAnsiString(const NewValue:AnsiString); procedure SetMyShortString(const NewValue:ShortString); published @@ -124,12 +137,51 @@ type property MyAnsiString:AnsiString read FMyAnsiString write SetMyAnsiString; property MyShortString:ShortString read FMyShortString write SetMyShortString; property MyBool:Boolean read FMyBool write FMyBool; - property MyBrush:TBrush read FMyBrush write FMyBrush; + //property MyBrush:TBrush read FMyBrush write FMyBrush; property MyPen:TPen read FMyPen write FMyPen; - property MyFont:TFont read FMyFont write FMyFont; - property MyComponent:TMyComponent read FMyComponent write FMyComponent; + //property MyFont:TFont read FMyFont write FMyFont; + //property MyComponent:TMyComponent read FMyComponent write FMyComponent; + property MyEvent:TNotifyEvent read FMyEvent write FMyEvent; end; + TMatBinaryObjectReader = class(TAbstractObjectReader) + private + FStream: TStream; + FBuffer: Pointer; + FBufSize: Integer; + FBufPos: Integer; + FBufEnd: Integer; + procedure Read(var Buf; Count: LongInt); + procedure SkipProperty; + procedure SkipSetBody; + public + constructor Create(Stream: TStream; BufSize: Integer); + destructor Destroy; override; + + function NextValue: TValueType; override; + function ReadValue: TValueType; override; + procedure BeginRootComponent; override; + procedure BeginComponent(var Flags: TFilerFlags; var AChildPos: Integer; + var CompClassName, CompName: AnsiString); override; + function BeginProperty: AnsiString; override; + + procedure ReadBinary(const DestData: TMemoryStream); override; + function ReadFloat: Extended; override; + function ReadSingle: Single; override; + {!!!: function ReadCurrency: Currency; override;} + function ReadDate: TDateTime; override; + function ReadIdent(ValueType: TValueType): AnsiString; override; + function ReadInt8: ShortInt; override; + function ReadInt16: SmallInt; override; + function ReadInt32: LongInt; override; + function ReadInt64: Int64; override; + function ReadSet(EnumType: Pointer): Integer; override; + function ReadStr: AnsiString; override; + function ReadString(StringType: TValueType): AnsiString; override; + procedure SkipComponent(SkipComponentInfos: Boolean); override; + procedure SkipValue; override; + end; + TMatBinaryObjectWriter = class(TAbstractObjectWriter) private FStream: TStream; @@ -173,6 +225,63 @@ var implementation +//============================================================================== + + + +{ TMyComponent } + +constructor TMyComponent.Create(AOwner:TComponent); +begin + inherited Create(AOwner); + Name:='MyComponent'; + FMyInteger:=-1234; + FMyCardinal:=5678; + FMySet:=[MyEnum1]; + FMyEnum:=MyEnum2; + FMyFloat:=3.2; + FMyBool:=true; + FMyAnsiString:='Ansi'; + FMyShortString:='Short'; + FMySubComponent:=TMySubComponent.Create(Self); + with FMySubComponent do begin + MyInteger:=789; + end; + FMyGraphicsObject:=nil; + FMyFont:=TFont.Create; + FMyBrush:=TBrush.Create; + FMyPen:=TPen.Create; + FMyEvent:=@DoSomething; + + MySubComponent2:=TMySubComponent.Create(Self); + with MySubComponent2 do begin + MyInteger:=1928; + end; +end; + +destructor TMyComponent.Destroy; +begin + FMyPen.Free; + FMyBrush.Free; + FMyFont.Free; + FMySubComponent.Free; + inherited Destroy; +end; + +procedure TMyComponent.SetMyAnsiString(const NewValue:AnsiString); +begin + FMyAnsiString:=NewValue; +end; + +procedure TMyComponent.SetMyShortString(const NewValue:ShortString); +begin + FMyShortString:=NewValue; +end; + +procedure TMyComponent.DoSomething(Sender:TObject); +begin + // +end; //============================================================================== @@ -182,7 +291,7 @@ procedure ObjectBinaryToText(Input, Output: TStream); procedure OutStr(s: String); begin - writeln('OutStr '''+s+''' NewTotalLen='+IntToStr(OutPut.Size)); + writeln('OutStr '''+s+''''); if Length(s) > 0 then Output.Write(s[1], Length(s)); end; @@ -287,13 +396,13 @@ procedure ObjectBinaryToText(Input, Output: TStream); var s: String; - len: LongInt; + //len: LongInt; IsFirst: Boolean; ext: Extended; begin writeln('ProcessValue Indent='''+Indent+''''); - OutStr('(' + IntToStr(Ord(Valuetype)) + ') '); +// OutStr('(' + IntToStr(Ord(Valuetype)) + ') '); case ValueType of vaList: begin OutStr('('); @@ -420,64 +529,614 @@ begin ReadObject(''); end; + + //============================================================================== -{ TMyComponent } -constructor TMyComponent.Create(AOwner:TComponent); -begin - inherited Create(AOwner); - Name:='MyComponent'; - FMyInteger:=-1234; - FMyCardinal:=5678; - FMySet:=[MyEnum1]; - FMyEnum:=MyEnum2; - FMyFloat:=3.2; - FMyBool:=true; - FMyAnsiString:='Ansi'; - FMyShortString:='Short'; - FMySubComponent:=TMySubComponent.Create(Self); - with FMySubComponent do begin - MyInteger:=789; +procedure ObjectTextToBinary(Input, Output: TStream); +var + parser: TParser; + + procedure WriteString(s: String); + begin + writeln('OTTB: WriteStr '''+s+''''); + Output.WriteByte(Length(s)); + Output.Write(s[1], Length(s)); end; - FMyGraphicsObject:=nil; - FMyFont:=TFont.Create; - FMyBrush:=TBrush.Create; - FMyPen:=TPen.Create; - FMyEvent:=@DoSomething; - MySubComponent2:=TMySubComponent.Create(Self); - with MySubComponent2 do begin - MyInteger:=1928; + procedure WriteInteger(value: LongInt); + begin + writeln('OTTB: WriteInteger '+IntToStr(Value)); + if (value >= -128) and (value <= 127) then begin + Output.WriteByte(Ord(vaInt8)); + Output.WriteByte(Byte(value)); + end else if (value >= -32768) and (value <= 32767) then begin + Output.WriteByte(Ord(vaInt16)); + Output.WriteWord(Word(value)); + end else begin + Output.WriteByte(ord(vaInt32)); + Output.WriteDWord(LongWord(value)); + end; + end; + + procedure ProcessProperty; forward; + + procedure ProcessValue; + var + flt: Extended; + s: String; + stream: TMemoryStream; + begin + writeln('OTTB: ProcessValue'); + case parser.Token of + toInteger: + begin + WriteInteger(parser.TokenInt); + parser.NextToken; + end; + toFloat: + begin + Output.WriteByte(Ord(vaExtended)); + flt := Parser.TokenFloat; + Output.Write(flt, SizeOf(flt)); + parser.NextToken; + end; + toString: + begin + s := parser.TokenString; + while parser.NextToken = '+' do + begin + parser.NextToken; // Get next string fragment + parser.CheckToken(toString); + s := s + parser.TokenString; + end; + Output.WriteByte(Ord(vaString)); + WriteString(s); + end; + toSymbol: + begin + if CompareText(parser.TokenString, 'True') = 0 then + Output.WriteByte(Ord(vaTrue)) + else if CompareText(parser.TokenString, 'False') = 0 then + Output.WriteByte(Ord(vaFalse)) + else if CompareText(parser.TokenString, 'nil') = 0 then + Output.WriteByte(Ord(vaNil)) + else + begin + Output.WriteByte(Ord(vaIdent)); + WriteString(parser.TokenString); + end; + Parser.NextToken; + end; + // Set + '[': + begin + parser.NextToken; + Output.WriteByte(Ord(vaSet)); + if parser.Token <> ']' then + while True do + begin + parser.CheckToken(toSymbol); + WriteString(parser.TokenString); + parser.NextToken; + if parser.Token = ']' then + break; + parser.CheckToken(','); + parser.NextToken; + end; + Output.WriteByte(0); + parser.NextToken; + end; + // List + '(': + begin + parser.NextToken; + Output.WriteByte(Ord(vaList)); + while parser.Token <> ')' do + ProcessValue; + Output.WriteByte(0); + parser.NextToken; + end; + // Collection + '<': + begin + parser.NextToken; + Output.WriteByte(Ord(vaCollection)); + while parser.Token <> '>' do + begin + parser.CheckTokenSymbol('item'); + parser.NextToken; + // ConvertOrder + Output.WriteByte(Ord(vaList)); + while not parser.TokenSymbolIs('end') do + ProcessProperty; + parser.NextToken; // Skip 'end' + Output.WriteByte(0); + end; + Output.WriteByte(0); + parser.NextToken; + end; + // Binary data + '{': + begin + Output.WriteByte(Ord(vaBinary)); + stream := TMemoryStream.Create; + try + parser.HexToBinary(stream); + Output.WriteDWord(stream.Size); + Output.Write(Stream.Memory^, stream.Size); + finally + stream.Free; + end; + parser.NextToken; + end; + else + begin + writeln('Error: Invalid property'); + halt; + //parser.Error(SInvalidProperty); + end; + end; + end; + + procedure ProcessProperty; + var + name: String; + begin + writeln('OTTB: ProcessProperty'); + // Get name of property + parser.CheckToken(toSymbol); + name := parser.TokenString; + while True do begin + parser.NextToken; + if parser.Token <> '.' then break; + parser.NextToken; + parser.CheckToken(toSymbol); + name := name + '.' + parser.TokenString; + end; + WriteString(name); + parser.CheckToken('='); + parser.NextToken; + ProcessValue; + end; + + procedure ProcessObject; + var + IsInherited: Boolean; + ObjectName, ObjectType: String; + begin + writeln('OTTB: ProcessObject'); + if parser.TokenSymbolIs('OBJECT') then + IsInherited := False + else begin + parser.CheckTokenSymbol('INHERITED'); + IsInherited := True; + end; + parser.NextToken; + parser.CheckToken(toSymbol); + ObjectName := ''; + ObjectType := parser.TokenString; + parser.NextToken; + if parser.Token = ':' then begin + parser.NextToken; + parser.CheckToken(toSymbol); + ObjectName := ObjectType; + ObjectType := parser.TokenString; + parser.NextToken; + end; + WriteString(ObjectType); + WriteString(ObjectName); + + // Convert property list + while not (parser.TokenSymbolIs('END') or + parser.TokenSymbolIs('OBJECT') or + parser.TokenSymbolIs('INHERITED')) do + ProcessProperty; + Output.WriteByte(0); // Terminate property list + + // Convert child objects + while not parser.TokenSymbolIs('END') do ProcessObject; + parser.NextToken; // Skip end token + Output.WriteByte(0); // Terminate property list + end; + +const + signature: PChar = 'TPF0'; +begin + parser := TParser.Create(Input); + try + Output.Write(signature[0], 4); + ProcessObject; + finally + parser.Free; end; end; -destructor TMyComponent.Destroy; + + +//============================================================================== + + +{ TMatBinaryObjectReader } + +constructor TMatBinaryObjectReader.Create(Stream: TStream; BufSize: Integer); begin - FMyPen.Free; - FMyBrush.Free; - FMyFont.Free; - FMySubComponent.Free; + writeln('MBOR: Create'); + inherited Create; + FStream := Stream; + FBufSize := BufSize; + GetMem(FBuffer, BufSize); +end; + +destructor TMatBinaryObjectReader.Destroy; +begin + writeln('MBOR: Destroy'); + { Seek back the amount of bytes that we didn't process unitl now: } + FStream.Seek(Integer(FBufPos) - Integer(FBufEnd), soFromCurrent); + + if Assigned(FBuffer) then + FreeMem(FBuffer, FBufSize); + inherited Destroy; end; -procedure TMyComponent.SetMyAnsiString(const NewValue:AnsiString); +function TMatBinaryObjectReader.ReadValue: TValueType; begin - FMyAnsiString:=NewValue; + writeln('MBOR: ReadValue'); + Result := vaNull; { Necessary in FPC as TValueType is larger than 1 byte! } + Read(Result, 1); end; -procedure TMyComponent.SetMyShortString(const NewValue:ShortString); +function TMatBinaryObjectReader.NextValue: TValueType; begin - FMyShortString:=NewValue; + writeln('MBOR: NextValue'); + Result := ReadValue; + { We only 'peek' at the next value, so seek back to unget the read value: } + Dec(FBufPos); end; -procedure TMyComponent.DoSomething(Sender:TObject); +procedure TMatBinaryObjectReader.BeginRootComponent; +var + Signature: LongInt; begin - // + writeln('MBOR: BeginRootComponent'); + { Read filer signature } + Read(Signature, 4); + if Signature <> LongInt(FilerSignature) then + raise EReadError.Create('SInvalidImage'); + //raise EReadError.Create(SInvalidImage); end; -//============================================================================== +procedure TMatBinaryObjectReader.BeginComponent(var Flags: TFilerFlags; + var AChildPos: Integer; var CompClassName, CompName: AnsiString); +var + Prefix: Byte; + ValueType: TValueType; +begin + writeln('MBOR: BeginComponent'); + { Every component can start with a special prefix: } + Flags := []; + if (Byte(NextValue) and $f0) = $f0 then + begin + Prefix := Byte(ReadValue); + Flags := TFilerFlags(Prefix and $0f); + if ffChildPos in Flags then + begin + ValueType := NextValue; + case ValueType of + vaInt8: + AChildPos := ReadInt8; + vaInt16: + AChildPos := ReadInt16; + vaInt32: + AChildPos := ReadInt32; + else + //raise EReadError.Create(SInvalidPropertyValue); + raise EReadError.Create('SInvalidPropertyValue'); + end; + end; + end; + + CompClassName := ReadStr; + CompName := ReadStr; + writeln('MBOR: BeginComponent! '''+CompClassName+''','''+CompName+''''); +end; + +function TMatBinaryObjectReader.BeginProperty: AnsiString; +begin + writeln('MBOR: BeginProperty'); + Result := ReadStr; + writeln('MBOR: BeginProperty! '''+Result+''''); +end; + +procedure TMatBinaryObjectReader.ReadBinary(const DestData: TMemoryStream); +var + BinSize: LongInt; +begin + writeln('MBOR: ReadBinary'); + Read(BinSize, 4); + DestData.Size := BinSize; + Read(DestData.Memory^, BinSize); +end; + +function TMatBinaryObjectReader.ReadFloat: Extended; +begin + writeln('MBOR: ReadFloat'); + Read(Result, SizeOf(Extended)); + writeln('MBOR: ReadFloat! '+FloatToStr(Result)); +end; + +function TMatBinaryObjectReader.ReadSingle: Single; +begin + writeln('MBOR: ReadSingle'); + Read(Result, SizeOf(Single)) +end; + +{!!!: function TMatBinaryObjectReader.ReadCurrency: Currency; +begin + writeln('MBOR: ReadCurrency'); + Read(Result, SizeOf(Currency)) +end;} + +function TMatBinaryObjectReader.ReadDate: TDateTime; +begin + writeln('MBOR: ReadDate'); + Read(Result, SizeOf(TDateTime)) +end; + +function TMatBinaryObjectReader.ReadIdent(ValueType: TValueType): AnsiString; +var + i: Byte; +begin + writeln('MBOR: ReadIdent'); + case ValueType of + vaIdent: + begin + Read(i, 1); + SetLength(Result, i); + Read(Pointer(@Result[1])^, i); + end; + vaNil: + Result := 'nil'; + vaFalse: + Result := 'False'; + vaTrue: + Result := 'True'; + vaNull: + Result := 'Null'; + end; + writeln('MBOR: ReadIdent! '''+Result+''''); +end; + +function TMatBinaryObjectReader.ReadInt8: ShortInt; +begin + Read(Result, 1); + writeln('MBOR: ReadInt8 '+IntToStr(Result)); +end; + +function TMatBinaryObjectReader.ReadInt16: SmallInt; +begin + Read(Result, 2); + writeln('MBOR: ReadInt16'+IntToStr(Result)); +end; + +function TMatBinaryObjectReader.ReadInt32: LongInt; +begin + Read(Result, 4); + writeln('MBOR: ReadInt32 '+IntToStr(Result)); +end; + +function TMatBinaryObjectReader.ReadInt64: Int64; +begin + Read(Result, 8); + writeln('MBOR: ReadInt64 '+IntToStr(Result)); +end; + +function TMatBinaryObjectReader.ReadSet(EnumType: Pointer): Integer; +var + Name: String; + Value: Integer; +begin + writeln('MBOR: ReadSet'); + try + while True do + begin + Name := ReadStr; + if Length(Name) = 0 then + break; + Value := GetEnumValue(PTypeInfo(EnumType), Name); + if Value = -1 then + //raise EReadError.Create(SInvalidPropertyValue); + raise EReadError.Create('SInvalidPropertyValue'); + Result := Result or Value; + end; + except + SkipSetBody; + raise; + end; + writeln('MBOR: ReadSet! '+IntToStr(Result)); +end; + +function TMatBinaryObjectReader.ReadStr: AnsiString; +var + i: Byte; +begin + writeln('MBOR: ReadStr'); + Read(i, 1); + SetLength(Result, i); + Read(Pointer(@Result[1])^, i); + writeln('MBOR: ReadStr! '''+Result+''''); +end; + +function TMatBinaryObjectReader.ReadString(StringType: TValueType): AnsiString; +var + i: Integer; +begin + writeln('MBOR: ReadString'); + case StringType of + vaString: + begin + i := 0; + Read(i, 1); + end; + vaLString: + Read(i, 4); + end; + SetLength(Result, i); + if i > 0 then + Read(Pointer(@Result[1])^, i); + writeln('MBOR: ReadString! '''+Result+''''); +end; + +{!!!: function TMatBinaryObjectReader.ReadWideString: WideString; +var + i: Integer; +begin + writeln('MBOR: ReadWideString'); + FDriver.Read(i, 4); + SetLength(Result, i); + if i > 0 then + Read(PWideChar(Result), i * 2); +end;} + +procedure TMatBinaryObjectReader.SkipComponent(SkipComponentInfos: Boolean); +var + Flags: TFilerFlags; + Dummy: Integer; + CompClassName, CompName: AnsiString; +begin + writeln('MBOR: SkipComponent Infos=',SkipComponentInfos); + if SkipComponentInfos then + { Skip prefix, component class name and component object name } + BeginComponent(Flags, Dummy, CompClassName, CompName); + + { Skip properties } + while NextValue <> vaNull do + SkipProperty; + ReadValue; + + { Skip children } + while NextValue <> vaNull do + SkipComponent(True); + ReadValue; +end; + +procedure TMatBinaryObjectReader.SkipValue; + + procedure SkipBytes(Count: LongInt); + var + Dummy: array[0..1023] of Byte; + SkipNow: Integer; + begin + while Count > 0 do + begin + if Count > 1024 then + SkipNow := 1024 + else + SkipNow := Count; + Read(Dummy, SkipNow); + Dec(Count, SkipNow); + end; + end; + +var + Count: LongInt; +begin + writeln('MBOR: SkipValue'); + case ReadValue of + vaNull, vaFalse, vaTrue, vaNil: ; + vaList: + begin + while NextValue <> vaNull do + SkipValue; + ReadValue; + end; + vaInt8: + SkipBytes(1); + vaInt16: + SkipBytes(2); + vaInt32: + SkipBytes(4); + vaExtended: + SkipBytes(SizeOf(Extended)); + vaString, vaIdent: + ReadStr; + vaBinary, vaLString, vaWString: + begin + Read(Count, 4); + SkipBytes(Count); + end; + vaSet: + SkipSetBody; + vaCollection: + begin + while NextValue <> vaNull do + begin + { Skip the order value if present } + if NextValue in [vaInt8, vaInt16, vaInt32] then + SkipValue; + SkipBytes(1); + while NextValue <> vaNull do + SkipProperty; + ReadValue; + end; + ReadValue; + end; + vaSingle: + SkipBytes(Sizeof(Single)); + {!!!: vaCurrency: + SkipBytes(SizeOf(Currency));} + vaDate: + SkipBytes(Sizeof(TDateTime)); + vaInt64: + SkipBytes(8); + end; +end; + +{ private methods } + +procedure TMatBinaryObjectReader.Read(var Buf; Count: LongInt); +var + CopyNow: LongInt; + Dest: Pointer; +begin + writeln('MBOR: Read Count='+IntToStr(Count)); + Dest := @Buf; + while Count > 0 do + begin + if FBufPos >= FBufEnd then + begin + FBufEnd := FStream.Read(FBuffer^, FBufSize); + if FBufEnd = 0 then + //raise EReadError.Create(SReadError); + raise EReadError.Create('SReadError'); + FBufPos := 0; + end; + CopyNow := FBufEnd - FBufPos; + if CopyNow > Count then + CopyNow := Count; + Move(PChar(FBuffer)[FBufPos], Dest^, CopyNow); + Inc(FBufPos, CopyNow); + Inc(Dest, CopyNow); + Dec(Count, CopyNow); + end; +end; + +procedure TMatBinaryObjectReader.SkipProperty; +begin + writeln('MBOR: SkipProperty'); + { Skip property name, then the property value } + ReadStr; + SkipValue; +end; + +procedure TMatBinaryObjectReader.SkipSetBody; +begin + writeln('MBOR: SkipSetBody'); + while Length(ReadStr) > 0 do; +end; @@ -737,6 +1396,8 @@ var i: Integer; begin writeln('MBOW: WriteStr '''+Value+''''); +// Mattias: What about strings > 255 ? +// Delphi does it the same, but how can this work ? i := Length(Value); if i > 255 then i := 255; @@ -772,21 +1433,27 @@ begin with FMyComponent do begin Name:='FMyComponent'; end; - - Name:='Form1'; - Caption := 'Test Form'; - OI:=nil; - OnShow:=@FormShow; - LoadMainMenu; - ActiveControl:=AddItemButton; - Left:=250; - Top:=50; + if FileExists(ClassName+'.lfm') then + LoadFromLFM + else begin + Name:='Form1'; + Caption:='Test Form'; + FMyEvent:=@WriteLFMButtonClick; + OnShow:=@FormShow; + Left:=250; + Top:=50; + LoadMainMenu; + ActiveControl:=Label1; + Show; + end; if OI=nil then begin OI:=TObjectInspector.Create(Application); - OI.Name:='OI'; - OI.SetBounds(7,50,220,700); - OI.Show; - OI.RootComponent:=Self; + with OI do begin + Name:='ObjectInspector'; + SetBounds(7,50,220,700); + RootComponent:=Self; + Show; + end; end; end; @@ -800,13 +1467,19 @@ Begin End; procedure TForm1.WriteLFMButtonClick(Sender:TObject); -var BinStream:TMemoryStream; +// demonstration of LFM and LFC files +// - streams current form to binary format (BinStream) +// - transforms binary format to text format (TmpTxtStream) +// - transforms text format back to binary format (TmpBinStream) +// - transforms binary format back to txtstream and save LFM file (TxtStream) +var BinStream,TmpTxtStream,TmpBinStream:TMemoryStream; Driver: TAbstractObjectWriter; Writer:TWriter; TxtStream:TFileStream; - s:string; begin BinStream:=TMemoryStream.Create; + TmpTxtStream:=TMemoryStream.Create; + TmpBinStream:=TMemoryStream.Create; try Driver:=TMatBinaryObjectWriter.Create(BinStream,4096); try @@ -819,19 +1492,74 @@ begin finally Driver.Free; end; - TxtStream:=TFileStream.Create(Name+'.lfm',fmCreate); + // transform binary to text and save LFM file + TxtStream:=TFileStream.Create(ClassName+'.lfm',fmCreate); try BinStream.Position:=0; ObjectBinaryToText(BinStream,TxtStream); finally TxtStream.Free; end; + // demonstrate transformation of text back to binary + writeln(''); + writeln('TRANFORMATION: binary to text ----------------'); + BinStream.Position:=0; + ObjectBinaryToText(BinStream,TmpTxtStream); + writeln(''); + writeln('TRANFORMATION: text back to binary ----------------'); + TmpTxtStream.Position:=0; + ObjectTextToBinary(TmpTxtStream,TmpBinStream); + writeln(''); + writeln('TRANFORMATION: binary to text file ----------------'); + TxtStream:=TFileStream.Create(ClassName+'.lfm2',fmCreate); + try + TmpBinStream.Position:=0; + ObjectBinaryToText(TmpBinStream,TxtStream); + finally + TxtStream.Free; + end; finally + TmpBinStream.Free; + TmpTxtStream.Free; BinStream.Free; end; writeln('Object written.'); end; +procedure TForm1.LoadFromLFM; +var + BinStream:TMemoryStream; + TxtStream:TFileStream; + Reader:TReader; +begin + // read LFM file and convert it to binary format + TxtStream:=TFileStream.Create(ClassName+'.lfm',fmOpenRead); + try + BinStream:=TMemoryStream.Create; + ObjectTextToBinary(TxtStream,BinStream); + finally + TxtStream.Free; + end; + // + BinStream.Position:=0; + Reader:=TReader.Create(BinStream,4096); + try + Reader.OnError:=@ReaderError; + Reader.OnFindMethod:=@ReaderFindMethod; + Reader.OnSetName:=@ReaderSetName; + Reader.OnReferenceName:=@ReaderReferenceName; + Reader.OnAncestorNotFound:=@ReaderAncestorNotFound; + Reader.OnCreateComponent:=@ReaderCreateComponent; + Reader.OnFindComponentClass:=@ReaderFindComponentClass; + writeln(''); + writeln('PARSING LFM ********************************************'); + Reader.ReadRootComponent(Self); + finally + Reader.Free; + end; + BinStream.Free; +end; + procedure TForm1.FormShow(Sender: TObject); begin end; @@ -890,36 +1618,82 @@ End; procedure TForm1.IndexButtonClick(Sender : TObject); var - s : shortstring; + s : shortstring; Begin - if assigned (ComboBox1) then - begin - s := Format ('%x', [ComboBox1.ItemIndex]); - if assigned (Memo1) - then Memo1.Lines.Add (s); - end; + if assigned (ComboBox1) then + begin + s := Format ('%x', [ComboBox1.ItemIndex]); + if assigned (Memo1) + then Memo1.Lines.Add (s); + end; End; procedure TForm1.ComboOnChange (Sender:TObject); var - s : shortstring; + s : shortstring; begin - if sender is TEdit - then s := 'TEdit' - else if sender is TComboBox - then s := 'TComboBox' - else - s := 'UNKNOWN'; - if assigned (Memo1) - then Memo1.Lines.Add (s + 'ONChange'); + if sender is TEdit + then s := 'TEdit' + else if sender is TComboBox + then s := 'TComboBox' + else + s := 'UNKNOWN'; + if assigned (Memo1) + then Memo1.Lines.Add (s + 'ONChange'); + if ComboBox1.Text='Create LFM' then + WriteLFMButtonClick(nil); end; procedure TForm1.ComboOnClick (Sender:TObject); begin - if assigned (Memo1) - then Memo1.Lines.Add ('ONClick'); + if assigned (Memo1) + then Memo1.Lines.Add ('ONClick'); end; +procedure TForm1.ReaderFindMethod(Reader: TReader; const FindMethodName: Ansistring; + var Address: Pointer; var Error: Boolean); +begin + writeln('ReaderFindMethod '''+FindMethodName+''''); +end; + +procedure TForm1.ReaderSetName(Reader: TReader; Component: TComponent; + var NewName: Ansistring); +begin + writeln('ReaderSetName OldName='''+Component.Name+''' NewName='''+NewName+''''); +end; + +procedure TForm1.ReaderReferenceName(Reader: TReader; var RefName: Ansistring); +begin + writeln('ReaderReferenceName Name='''+RefName+''''); +end; + +procedure TForm1.ReaderAncestorNotFound(Reader: TReader; const ComponentName: Ansistring; + ComponentClass: TPersistentClass; var Component: TComponent); +begin + writeln('ReaderAncestorNotFound ComponentName='''+ComponentName + +''' Component='''+Component.Name+''''); +end; + +procedure TForm1.ReaderError(Reader: TReader; const Message: Ansistring; + var Handled: Boolean); +begin + writeln('ReaderError '''+Message+''''); +end; + +procedure TForm1.ReaderFindComponentClass(Reader: TReader; const FindClassName: Ansistring; + var ComponentClass: TComponentClass); +begin + writeln('ReaderFindComponentClass ClassName='''+ClassName+''''); +end; + +procedure TForm1.ReaderCreateComponent(Reader: TReader; + ComponentClass: TComponentClass; var Component: TComponent); +begin + writeln('ReaderCreateComponent Class='''+ComponentClass.ClassName+''''); +end; + + + {------------------------------------------------------------------------------} procedure TForm1.LoadMainMenu; @@ -930,7 +1704,7 @@ begin Height := 400; Width := 700; - OIResizeButton:=TButton.Create(Self); +{ OIResizeButton:=TButton.Create(Self); with OIResizeButton do begin Name:='OIResizeButton'; Parent:=Self; @@ -960,119 +1734,131 @@ begin Show; end; - { Create 2 buttons inside the groupbox } + // Create 2 buttons inside the groupbox EditToComboButton := TButton.Create(Self); - EditToComboButton.Name:='EditToComboButton'; - EditToComboButton.Parent := Self; - EditToComboButton.Left := 50; - EditToComboButton.Top := 80; - EditToComboButton.Width := 120; - EditToComboButton.Height := 30; - EditToComboButton.Show; - EditToComboButton.Caption := 'Edit->Combo'; - EditToComboButton.OnClick := @EditToComboButtonClick; + with EditToComboButton do begin + Name:='EditToComboButton'; + Parent := Self; + Left := 50; + Top := 80; + Width := 120; + Height := 30; + Caption := 'Edit->Combo'; + OnClick := @EditToComboButtonClick; + Show; + end; AddItemButton := TButton.Create(Self); - AddItemButton.Name:='AddItemButton'; - AddItemButton.Parent := Self; - AddItemButton.Left := 50; - AddItemButton.Top := 40; - AddItemButton.Width := 120; - AddItemButton.Height := 30; - AddItemButton.Show; - AddItemButton.Caption := 'Add item'; - AddItemButton.OnClick := @AddItemButtonClick; + with AddItemButton do begin + Name:='AddItemButton'; + Parent := Self; + Left := 50; + Top := 40; + Width := 120; + Height := 30; + Caption := 'Add item'; + OnClick := @AddItemButtonClick; + Show; + end; - { Create 2 more buttons outside the groupbox } + // Create 2 more buttons outside the groupbox ComboToEditButton := TButton.Create(Self); - ComboToEditButton.Name:='ComboToEditButton'; - ComboToEditButton.Parent := Self; - ComboToEditButton.Left := 50; - ComboToEditButton.Top := 120; - ComboToEditButton.Width := 120; - ComboToEditButton.Height := 30; - ComboToEditButton.Show; - ComboToEditButton.Caption := 'Combo->Edit'; - ComboToEditButton.OnClick := @ComboToEditButtonClick; - + with ComboToEditButton do begin + Name:='ComboToEditButton'; + Parent := Self; + Left := 50; + Top := 120; + Width := 120; + Height := 30; + Caption := 'Combo->Edit'; + OnClick := @ComboToEditButtonClick; + Show; + end; SwitchEnabledButton := TButton.Create(Self); - SwitchEnabledButton.Name:='SwitchEnabledButton'; - SwitchEnabledButton.Parent := Self; - SwitchEnabledButton.Left := 50; - SwitchEnabledButton.Top := 160; - SwitchEnabledButton.Width := 120; - SwitchEnabledButton.Height := 30; - SwitchEnabledButton.Show; - SwitchEnabledButton.Caption := 'Enabled On/Off'; - SwitchEnabledButton.OnClick := @SwitchEnabledButtonClick; + with SwitchEnabledButton do begin + Name:='SwitchEnabledButton'; + Parent := Self; + Left := 50; + Top := 160; + Width := 120; + Height := 30; + Caption := 'Enabled On/Off'; + OnClick := @SwitchEnabledButtonClick; + Show; + end; DumpButton := TButton.Create(Self); - DumpButton.Name:='DumpButton'; - DumpButton.Parent := Self; - DumpButton.Left := 50; - DumpButton.Top := 200; - DumpButton.Width := 120; - DumpButton.Height := 30; - DumpButton.Show; - DumpButton.Caption := 'Dump'; - DumpButton.OnClick := @DumpButtonClick; + with DumpButton do begin + Name:='DumpButton'; + Parent := Self; + Left := 50; + Top := 200; + Width := 120; + Height := 30; + Caption := 'Dump'; + OnClick := @DumpButtonClick; + Show; + end; IndexButton := TButton.Create(Self); - IndexButton.Name:='IndexButton'; - IndexButton.Parent := Self; - IndexButton.Left := 50; - IndexButton.Top := 240; - IndexButton.Width := 120; - IndexButton.Height := 30; - IndexButton.Show; - IndexButton.Caption := 'Index ?'; - IndexButton.OnClick := @IndexButtonClick; + with IndexButton do begin + Name:='IndexButton'; + Parent := Self; + Left := 50; + Top := 240; + Width := 120; + Height := 30; + Caption := 'Index ?'; + OnClick := @IndexButtonClick; + Show; + end; - - { Create a label for the edit field } - label1 := TLabel.Create(Self); - Label1.Name:='Label1'; - label1.Parent := self; - label1.top := 50; - label1.left := 320; - label1.Height := 20; - label1.Width := 130; - label1.Show; - label1.Caption := 'TEdit :'; +} + // Create a label for the edit field + Label1 := TLabel.Create(Self); + with Label1 do begin + Name:='Label1'; + Parent := self; + top := 50; + left := 320; + Height := 20; + Width := 130; + Caption := 'TEdit :'; + Show; + end; Edit1 := TEdit.Create (self); with Edit1 do begin - Name := 'Edit1'; - Parent := self; - Left := 500; - Top := 50; - Width := 70; - Height := 20; - OnChange := @ComboOnChange; - OnClick := @ComboOnClick; - Show; + Name := 'Edit1'; + Parent := self; + Left := 500; + Top := 50; + Width := 70; + Height := 20; + OnChange := @ComboOnChange; + OnClick := @ComboOnClick; + Show; end; - { Create a label for the 1st combobox } - label2 := TLabel.Create(Self); - Label2.Name:='Label2'; - label2.Parent := self; - label2.top := 100; - label2.left := 320; - label2.Height := 20; - label2.Width := 130; - label2.Enabled:= true; - label2.Show; - label2.Caption := 'Combo (unsorted)'; - label2.Enabled:= true; + // Create a label for the 1st combobox + Label2 := TLabel.Create(Self); + with Label2 do begin + Name:='Label2'; + Parent := self; + top := 100; + left := 320; + Height := 20; + Width := 130; + Caption := 'Combo (unsorted)'; + Show; + end; - - { Create the menu now } + // Create the menu now { WARNING: If you do it after creation of the combo, the menu will not appear. Reason is unknown by now!!!!!!} - mnuMain := TMainMenu.Create(Self); + {mnuMain := TMainMenu.Create(Self); mnuMain.Name:='mnuMain'; Menu := mnuMain; itmFile := TMenuItem.Create(Self); @@ -1083,7 +1869,7 @@ begin itmFileQuit.Name:='itmFileQuit'; itmFileQuit.Caption := '&Quit'; itmFileQuit.OnClick := @mnuQuitClicked; - itmFile.Add(itmFileQuit); + itmFile.Add(itmFileQuit);} ComboBox1 := TComboBox.Create (self); with ComboBox1 do @@ -1100,6 +1886,7 @@ begin ItemIndex := 1; Items.Add ('33333!'); Items.Add ('abcde!'); + Items.Add ('Create LFM'); OnChange := @ComboOnChange; OnClick := @ComboOnClick; Show; @@ -1107,15 +1894,17 @@ begin { Create a label for the 2nd combobox } - label3 := TLabel.Create(Self); - Label3.Name:='Label3'; - label3.Parent := self; - label3.top := 150; - label3.left := 320; - label3.Height := 20; - label3.Width := 130; - label3.Show; - label3.Caption := 'Combo (sorted)'; + Label3 := TLabel.Create(Self); + with Label3 do begin + Name:='Label3'; + Parent := self; + top := 150; + left := 320; + Height := 20; + Width := 130; + Caption := 'Combo (sorted)'; + Show; + end; ComboBox2 := TComboBox.Create (self); @@ -1149,10 +1938,10 @@ begin end; {------------------------------------------------------------------------------} -procedure TForm1.mnuQuitClicked(Sender : TObject); +{procedure TForm1.mnuQuitClicked(Sender : TObject); begin Application.Terminate; -end; +end; } {------------------------------------------------------------------------------} diff --git a/ide/customformeditor.pp b/ide/customformeditor.pp index bf31255bc2..0f21c051a7 100644 --- a/ide/customformeditor.pp +++ b/ide/customformeditor.pp @@ -30,58 +30,55 @@ uses Const OrdinalTypes = [tkInteger,tkChar,tkENumeration,tkbool]; type - - { TComponentInterface is derived from TIComponentInterface. It gives access to each control that's dropped onto the form } -TCustomFormEditor = class; //forward declaration -TSetProc = Procedure (const Value) of Object; -TGetProc = Function : Variant of Object; - - + TCustomFormEditor = class; //forward declaration + TSetProc = Procedure (const Value) of Object; + TGetProc = Function : Variant of Object; TComponentInterface = class(TIComponentInterface) - private - FControl : TComponent; - FFormEditor : TCustomFormEditor; //used to call it's functions - Function FSetProp(PRI : PPropInfo; const Value) : Boolean; - Function FGetProp(PRI : PPropInfo; var Value) : Boolean; - protected - Function GetPPropInfobyIndex(Index : Integer) : PPropInfo; - Function GetPPropInfobyName(Name : String) : PPropInfo; - MySetProc : TSetPRoc; - MyGetProc : TGetProc; - public - constructor Create; - destructor Destroy; override; + private + FControl : TComponent; + FFormEditor : TCustomFormEditor; //used to call it's functions + Function FSetProp(PRI : PPropInfo; const Value) : Boolean; + Function FGetProp(PRI : PPropInfo; var Value) : Boolean; - Function GetComponentType : String; override; - Function GetComponentHandle : LongInt; override; - Function GetParent : TIComponentInterface; override; - Function IsTControl : Boolean; override; - Function GetPropCount : Integer; override; - Function GetPropType(Index : Integer) : TTypeKind; override; - Function GetPropName(Index : Integer) : String; override; - Function GetPropTypebyName(Name : String) : TTypeKind; override; + protected + Function GetPPropInfobyIndex(Index : Integer) : PPropInfo; + Function GetPPropInfobyName(Name : String) : PPropInfo; + MySetProc : TSetPRoc; + MyGetProc : TGetProc; + public + constructor Create; + destructor Destroy; override; - Function GetPropValue(Index : Integer; var Value) : Boolean; override; - Function GetPropValuebyName(Name: String; var Value) : Boolean; override; - Function SetProp(Index : Integer; const Value) : Boolean; override; - Function SetPropbyName(Name : String; const Value) : Boolean; override; + Function GetComponentType : String; override; + Function GetComponentHandle : LongInt; override; + Function GetParent : TIComponentInterface; override; + Function IsTControl : Boolean; override; + Function GetPropCount : Integer; override; + Function GetPropType(Index : Integer) : TTypeKind; override; + Function GetPropName(Index : Integer) : String; override; + Function GetPropTypebyName(Name : String) : TTypeKind; override; - Function GetControlCount: Integer; override; - Function GetControl(Index : Integer): TIComponentInterface; override; + Function GetPropValue(Index : Integer; var Value) : Boolean; override; + Function GetPropValuebyName(Name: String; var Value) : Boolean; override; + Function SetProp(Index : Integer; const Value) : Boolean; override; + Function SetPropbyName(Name : String; const Value) : Boolean; override; - Function GetComponentCount: Integer; override; - Function GetComponent(Index : Integer): TIComponentInterface; override; + Function GetControlCount: Integer; override; + Function GetControl(Index : Integer): TIComponentInterface; override; - Function Select : Boolean; override; - Function Focus : Boolean; override; - Function Delete : Boolean; override; - property Control : TComponent read FCOntrol; + Function GetComponentCount: Integer; override; + Function GetComponent(Index : Integer): TIComponentInterface; override; + + Function Select : Boolean; override; + Function Focus : Boolean; override; + Function Delete : Boolean; override; + property Control : TComponent read FCOntrol; end; { @@ -98,9 +95,7 @@ TCustomFormEditor FSelectedComponents : TComponentSelectionList; FObj_Inspector : TObjectInspector; protected - public - constructor Create; destructor Destroy; override; @@ -111,8 +106,8 @@ TCustomFormEditor Function FindComponent(AComponent: TComponent): TIComponentInterface; override; Function GetFormComponent : TIComponentInterface; override; // Function CreateComponent(CI : TIComponentInterface; TypeName : String; - Function CreateComponent(CI : TIComponentInterface; TypeClass : TComponentClass; - X,Y,W,H : Integer): TIComponentInterface; override; + Function CreateComponent(ParentCI : TIComponentInterface; + TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface; override; Procedure ClearSelected; property SelectedComponents : TComponentSelectionList read FSelectedComponents write FSelectedComponents; property Obj_Inspector : TObjectInspector read FObj_Inspector write FObj_Inspector; @@ -121,54 +116,59 @@ TCustomFormEditor implementation + uses SysUtils; - - {TComponentInterface} constructor TComponentInterface.Create; begin -inherited; + inherited Create; end; destructor TComponentInterface.Destroy; begin -inherited; + inherited Destroy; end; -Function TComponentInterface.FSetProp(PRI : PPropInfo; const Value) : Boolean; +Function TComponentInterface.FSetProp(PRI : PPropInfo; +const Value) : Boolean; Begin - case PRI^.PropType^.Kind of - tkBool: SetOrdProp(FControl,PRI,longint(Value)); - tkSString, - tkLString, - tkAString, - tkWString : Begin - Writeln('String...'); - SetStrProp(FControl,PRI,String(Value)); - end; - tkInteger, - tkInt64 : Begin - Writeln('Int64...'); - SetInt64Prop(FControl,PRI,Int64(Value)); - end; - tkFloat : Begin - Writeln('Float...'); - SetFloatProp(FControl,PRI,Extended(Value)); - end; - tkVariant : Begin - Writeln('Variant...'); - SetVariantProp(FControl,PRI,Variant(Value)); - end; - tkMethod : Begin - Writeln('Method...'); - SetMethodProp(FControl,PRI,TMethod(value)); - end; - else - Result := False; - end;//case + case PRI^.PropType^.Kind of + tkBool: SetOrdProp(FControl,PRI,longint(Value)); + tkSString, + tkLString, + tkAString, + tkWString : Begin + Writeln('String...'); + SetStrProp(FControl,PRI,String(Value)); + Result := True; + end; + tkInteger, + tkInt64 : Begin + Writeln('Int64...'); + SetInt64Prop(FControl,PRI,Int64(Value)); + Result := True; + end; + tkFloat : Begin + Writeln('Float...'); + SetFloatProp(FControl,PRI,Extended(Value)); + Result := True; + end; + tkVariant : Begin + Writeln('Variant...'); + SetVariantProp(FControl,PRI,Variant(Value)); + Result := True; + end; + tkMethod : Begin + Writeln('Method...'); + SetMethodProp(FControl,PRI,TMethod(value)); + Result := True; + end; + else + Result := False; + end;//case end; Function TComponentInterface.FGetProp(PRI : PPropInfo; var Value) : Boolean; @@ -208,20 +208,23 @@ Result := True; end; + + + Function TComponentInterface.GetPPropInfoByIndex(Index:Integer): PPropInfo; var -PT : PTypeData; -PP : PPropList; -PI : PTypeInfo; + PT : PTypeData; + PP : PPropList; + PI : PTypeInfo; Begin PI := FControl.ClassInfo; PT:=GetTypeData(PI); GetMem (PP,PT^.PropCount*SizeOf(Pointer)); GetPropInfos(PI,PP); if Index < PT^.PropCount then - Result:=PP^[index] - else - Result := nil; + Result:=PP^[index] + else + Result := nil; //does freeing this kill my result? Check this... // Freemem(PP); @@ -229,10 +232,10 @@ end; Function TComponentInterface.GetPPropInfoByName(Name:String): PPropInfo; var -PT : PTypeData; -PP : PPropList; -PI : PTypeInfo; -I : Longint; + PT : PTypeData; + PP : PPropList; + PI : PTypeInfo; + I : Longint; Begin Name := Uppercase(name); PI := FControl.ClassInfo; @@ -241,39 +244,39 @@ Begin GetPropInfos(PI,PP); I := -1; repeat - inc(i); + inc(i); until (PP^[i]^.Name = Name) or (i = PT^.PropCount-1); if PP^[i]^.Name = Name then - Result:=PP^[i] - else - Result := nil; + Result:=PP^[i] + else + Result := nil; //does freeing this kill my result? Check this... // Freemem(PP); end; - Function TComponentInterface.GetComponentType : String; Begin //???What do I return? TObject's Classtype? + Result:=FControl.ClassName; end; Function TComponentInterface.GetComponentHandle : LongInt; Begin //return the TWinControl handle? -if (FControl is TWinControl) then -Result := TWinControl(FControl).Handle; + if (FControl is TWinControl) then + Result := TWinControl(FControl).Handle; end; Function TComponentInterface.GetParent : TIComponentInterface; Begin -result := nil; -if (FCOntrol is TControl) then -if TControl(FControl).Parent <> nil then - begin - Result := FFormEditor.FindComponentByName(TControl(FControl).Parent.Name); - end; + result := nil; + if (FCOntrol is TControl) then + if TControl(FControl).Parent <> nil then + begin + Result := FFormEditor.FindComponent(TControl(FControl).Parent); + end; end; Function TComponentInterface.IsTControl : Boolean; @@ -283,11 +286,10 @@ end; Function TComponentInterface.GetPropCount : Integer; var -PT : PTypeData; + PT : PTypeData; Begin -PT:=GetTypeData(FControl.ClassInfo); - -Result := PT^.PropCount; + PT:=GetTypeData(FControl.ClassInfo); + Result := PT^.PropCount; end; Function TComponentInterface.GetPropType(Index : Integer) : TTypeKind; @@ -297,7 +299,8 @@ PP : PPropList; PI : PTypeInfo; Num : Integer; Begin - PT:=GetTypeData(FControl.ClassInfo); + PI:=FControl.ClassInfo; + PT:=GetTypeData(PI); GetMem (PP,PT^.PropCount*SizeOf(Pointer)); GetPropInfos(PI,PP); if Index < PT^.PropCount then @@ -315,7 +318,8 @@ PP : PPropList; PI : PTypeInfo; Num : Integer; Begin - PT:=GetTypeData(FControl.ClassInfo); + PI:=FControl.ClassInfo; + PT:=GetTypeData(PI); GetMem (PP,PT^.PropCount*SizeOf(Pointer)); GetPropInfos(PI,PP); if Index < PT^.PropCount then @@ -323,37 +327,34 @@ Begin else Result := ''; freemem(PP); - end; Function TComponentInterface.GetPropTypebyName(Name : String) : TTypeKind; var -PT : PTypeData; -PP : PPropList; -PI : PTypeInfo; -Num : Integer; -I : Longint; + PT : PTypeData; + PP : PPropList; + PI : PTypeInfo; + I : Longint; Begin - PT:=GetTypeData(FControl.ClassInfo); + PI:=FControl.ClassInfo; + PT:=GetTypeData(PI); GetMem (PP,PT^.PropCount*SizeOf(Pointer)); GetPropInfos(PI,PP); Result := tkUnknown; For I:=0 to PT^.PropCount-1 do If PP^[i]<>Nil then - begin - if PP^[i]^.Name = Name then - begin - Result := PP^[i]^.PropType^.Kind; - Break; - end; - end; + begin + if PP^[i]^.Name = Name then + begin + Result := PP^[i]^.PropType^.Kind; + Break; + end; + end; freemem(PP); - end; - Function TComponentInterface.GetPropValue(Index : Integer; var Value) : Boolean; var PP : PPropInfo; @@ -385,94 +386,98 @@ Begin end; end; + Function TComponentInterface.SetPropbyName(Name : String; const Value) : Boolean; var -PRI : PPropInfo; + PRI : PPropInfo; Begin -Result := False; + Writeln('SetPropByName Name='''+Name+''''); + Result := False; -PRI := GetPropInfo(FControl.ClassInfo,Name); -if PRI <> nil then - Begin - Result :=FSetProp(PRI,Value); - end; + PRI := GetPropInfo(FControl.ClassInfo,Name); + if PRI <> nil then + Begin + Result :=FSetProp(PRI,Value); + end; end; - Function TComponentInterface.GetControlCount: Integer; Begin + // XXX Todo: end; Function TComponentInterface.GetControl(Index : Integer): TIComponentInterface; Begin + // XXX Todo: end; - Function TComponentInterface.GetComponentCount: Integer; Begin + // XXX Todo: end; Function TComponentInterface.GetComponent(Index : Integer): TIComponentInterface; Begin + // XXX Todo: end; - Function TComponentInterface.Select : Boolean; Begin + // XXX Todo: end; Function TComponentInterface.Focus : Boolean; Begin + // XXX Todo: end; Function TComponentInterface.Delete : Boolean; Begin + // XXX Todo: end; - - {TCustomFormEditor} constructor TCustomFormEditor.Create; begin -inherited Create; -FComponentInterfaceList := TList.Create; -FSelectedComponents := TComponentSelectionList.Create; + inherited Create; + FComponentInterfaceList := TList.Create; + FSelectedComponents := TComponentSelectionList.Create; end; destructor TCustomFormEditor.Destroy; begin -inherited; -FComponentInterfaceList.Destroy; -FSelectedComponents.Destroy; + inherited; + FComponentInterfaceList.Free; + FSelectedComponents.Free; end; Function TCustomFormEditor.AddSelected(Value : TComponent) : Integer; Begin -Result := -1; -FSelectedComponents.Add(Value); -Result := FSelectedComponents.Count; -//call the OI to update it's selected. -Obj_Inspector.Selections := FSelectedComponents; + FSelectedComponents.Add(Value); + Result := FSelectedComponents.Count; + // call the OI to update it's selected. + writeln('[TCustomFormEditor.AddSelected] '+Value.Name); + Obj_Inspector.Selections := FSelectedComponents; end; Function TCustomFormEditor.Filename : String; begin -Result := 'testing.pp'; + Result := 'testing.pp'; end; Function TCustomFormEditor.FormModified : Boolean; Begin -Result := FModified; + Result := FModified; end; Function TCustomFormEditor.FindComponentByName(const Name : String) : TIComponentInterface; @@ -481,156 +486,170 @@ Var Begin Num := 0; While Num < FComponentInterfaceList.Count do - Begin - Result := TIComponentInterface(FComponentInterfaceList.Items[Num]); - if TComponentInterface(Result).FControl.Name = Name then break; - inc(num); - end; + Begin + Result := TIComponentInterface(FComponentInterfaceList.Items[Num]); + if Upcase(TComponentInterface(Result).FControl.Name) = UpCase(Name) then + exit; + inc(num); + end; + Result:=nil; end; - -Function TCustomFormEditor.FindComponent(AComponent: TComponent) : TIComponentInterface; +Function TCustomFormEditor.FindComponent(AComponent:TComponent): TIComponentInterface; Var Num : Integer; Begin Num := 0; While Num < FComponentInterfaceList.Count do - Begin - Result := TIComponentInterface(FComponentInterfaceList.Items[Num]); - if TComponentInterface(Result).FControl = AComponent then break; - inc(num); - end; + Begin + Result := TIComponentInterface(FComponentInterfaceList.Items[Num]); + if TComponentInterface(Result).FControl = AComponent then exit; + inc(num); + end; + Result:=nil; end; //Function TCustomFormEditor.CreateComponent(CI : TIComponentInterface; TypeName : String; -Function TCustomFormEditor.CreateComponent(CI : TIComponentInterface; TypeClass : TComponentClass; - X,Y,W,H : Integer): TIComponentInterface; +Function TCustomFormEditor.CreateComponent( +ParentCI : TIComponentInterface; +TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface; Var -Temp : TComponentInterface; -TempInterface : TComponentInterface; -TempClass : TPersistentClass; -TempName : String; -Found : Boolean; -I, Num : Integer; + Temp : TComponentInterface; + TempInterface : TComponentInterface; + TempClass : TPersistentClass; + TempName : String; + Found : Boolean; + I, Num : Integer; + CompLeft, CompTop, CompWidth, CompHeight: integer; + DummyComponent:TComponent; Begin -Temp := TComponentInterface.Create; -Writeln('TComponentInterface created......'); -if SelectedComponents.Count = 0 then -Temp.FControl := TypeClass.Create(nil) -else -Begin -Writeln('Selected Components > 0'); -if (SelectedComponents.Items[0] is TWinControl) and (csAcceptsControls in TWinControl(SelectedComponents.Items[0]).ControlStyle) then + writeln('[TCustomFormEditor.CreateComponent] Class='''+TypeClass.ClassName+''''); + Temp := TComponentInterface.Create; + Writeln('TComponentInterface created......'); + if Assigned(ParentCI) then begin + if Assigned(TComponentInterface(ParentCI).FControl.Owner) then + Temp.FControl := + TypeClass.Create(TComponentInterface(ParentCI).FControl.Owner) + else + Temp.FControl := + TypeClass.Create(TComponentInterface(ParentCI).FControl) + end else + Temp.FControl := TypeClass.Create(nil); +{ if SelectedComponents.Count = 0 then + else + Begin + Writeln('Selected Components > 0'); + if (SelectedComponents.Items[0] is TWinControl) + and (csAcceptsControls in + TWinControl(SelectedComponents.Items[0]).ControlStyle) then Begin - Writeln('The Control is a TWinControl and it accepts controls'); - Writeln('The owners name is '+TWinControl(SelectedComponents.Items[0]).Name); - Temp.FControl := TypeClass.Create(SelectedComponents.Items[0]); + Writeln('The Control is a TWinControl and it accepts controls'); + Writeln('The owners name is '+TWinControl(SelectedComponents.Items[0]).Name); + Temp.FControl := TypeClass.Create(SelectedComponents.Items[0]); end else Begin - Writeln('The Control is not a TWinControl or it does not accept controls'); - Temp.FControl := TypeClass.Create(SelectedComponents.Items[0].Owner); + Writeln('The Control is not a TWinControl or it does not accept controls'); + Temp.FControl := TypeClass.Create(SelectedComponents.Items[0].Owner); end; -end; + end;} -//create a name for the control + Writeln('4'); - -TempName := Temp.FControl.ClassName; -delete(TempName,1,1); -writeln('TempName is ....'+TempName); -Found := True; -Num := 0; -While Found do - Begin - Found := False; - inc(num); - Writeln('NUm = '+inttostr(num)); - for I := 0 to FComponentInterfaceList.Count-1 do - begin - if TComponent(TComponentInterface(FComponentInterfaceList.Items[i]).FControl).Name = TempName+inttostr(Num) then - begin - Found := True; - break; - end; - end; - end; -Temp.FControl.Name := TempName+Inttostr(num); -Writeln('TempName + num = '+TempName+Inttostr(num)); - - -Writeln('4'); - - if Assigned(CI) then - Begin - if (TComponentInterface(CI).FControl is TWinControl) and - (csAcceptsControls in TWinControl(TComponentInterface(CI).FControl).COntrolStyle)then - begin - TWinControl(Temp.FControl).Parent := TWinControl(TComponentInterface(CI).FControl); - end - else - TWinControl(Temp.FControl).Parent := TWinControl(TComponentInterface(CI).FControl).Parent; - - - End - else - Begin //CI is not assigned so check the selected control - Writeln('CI is not assigned....'); - if SelectedComponents.Count > 0 then + if Assigned(ParentCI) then + Begin + if (TComponentInterface(ParentCI).FControl is TWinControl) + and (csAcceptsControls in + TWinControl(TComponentInterface(ParentCI).FControl).ControlStyle) then + begin + TWinControl(Temp.FControl).Parent := + TWinControl(TComponentInterface(ParentCI).FControl); + writeln('Parent is '''+TWinControl(Temp.FControl).Parent.Name+''''); + end + else + begin + TWinControl(Temp.FControl).Parent := + TWinControl(TComponentInterface(ParentCI).FControl).Parent; + writeln('Parent is '''+TWinControl(Temp.FControl).Parent.Name+''''); + end; +{ End + else + Begin //ParentCI is not assigned so check the selected control + Writeln('ParentCI is not assigned....'); + if SelectedComponents.Count > 0 then Begin - Writeln('CI is not assigned but something is selected....'); - TempInterface := TComponentInterface(FindComponentByName(SelectedComponents.Items[0].Name)); - Writeln('The selected control is....'+TempInterface.FControl.Name); + Writeln('ParentCI is not assigned but something is selected....'); + TempInterface := TComponentInterface( + FindComponent(SelectedComponents.Items[0])); + Writeln('The selected control is '''+TempInterface.FControl.Name+''''); + + if (TempInterface.FControl is TWinControl) and + (csAcceptsControls in + TWinControl(TempInterface.FControl).ControlStyle) then + Begin + Writeln('The selected control IS a TWincontrol and accepts controls'); + TWinControl(Temp.FControl).Parent := + TWinControl(TempInterface.FControl); + end + else + TWinControl(Temp.FControl).Parent := + TWinControl(TempInterface.FControl).Parent; + end} + end; - if (TempInterface.FControl is TWinControl) and - (csAcceptsControls in TWinControl(TempInterface.FControl).ControlStyle)then - Begin - Writeln('The selected control IS a TWincontrol and accepts controls'); - TWinControl(Temp.FControl).Parent := TWinControl(TempInterface.FControl); - end - else - TWinControl(Temp.FControl).Parent := TWinControl(TempInterface.FControl).Parent; - end - end; Writeln('5'); + TempName := Temp.FControl.ClassName; + delete(TempName,1,1); + writeln('TempName is '''+TempName+''''); + Num := 0; + Found := True; + While Found do + Begin + Found := False; + inc(num); + for I := 0 to FComponentInterfaceList.Count-1 do + begin + DummyComponent:=TComponent(TComponentInterface( + FComponentInterfaceList.Items[i]).FControl); + if UpCase(DummyComponent.Name)=UpCase(TempName+IntToStr(Num)) then + begin + Found := True; + break; + end; + end; + end; + Temp.FControl.Name := TempName+IntToStr(Num); + Writeln('TempName + num = '+TempName+Inttostr(num)); + if (Temp.FControl is TControl) then + Begin + CompLeft:=X; + CompTop:=Y; + CompWidth:=W; + CompHeight:=H; + if CompWidth<=0 then CompWidth:=TControl(Temp.FControl).Width; + if CompHeight<=0 then CompHeight:=TControl(Temp.FControl).Height; + if CompLeft<0 then + CompLeft:=(TControl(Temp.FControl).Parent.Width + CompWidth) div 2; + if CompTop<0 then + CompTop:=(TControl(Temp.FControl).Parent.Height+ CompHeight) div 2; + TControl(Temp.FControl).SetBounds(CompLeft,CompTop,CompWidth,CompHeight); + end; -if (Temp.FControl is TControl) then - Begin - if (X <> -1) and (Y <> -1) and (W <> -1) and (H <> -1) then - TControl(Temp.FControl).SetBounds(X,Y,W,H) - else - Begin - if (W <> -1) then TControl(Temp.FControl).Width := W; //if W=-1 then use default size otherwise use W + FComponentInterfaceList.Add(Temp); - if (H <> -1) then TControl(Temp.FControl).Height := H; //if H=-1 then use default size otherwise use H - - if (X <> -1) then TControl(Temp.FControl).Left := X //if X=-1 then center in parent otherwise use X - else - TControl(Temp.FControl).Left := (TControl(Temp.FControl).Parent.Width div 2) - (TControl(Temp.FControl).Width div 2); - - if (Y <> -1) then TControl(Temp.FControl).Top := Y //if Y=-1 then center in parent otherwise use Y - else - TControl(Temp.FControl).Top := (TControl(Temp.FControl).Parent.Height div 2) - (TControl(Temp.FControl).Height div 2); - end; - - end; - - -FComponentInterfaceList.Add(Temp); - - Result := Temp; + Result := Temp; end; Function TCustomFormEditor.GetFormComponent : TIComponentInterface; Begin -//this can only be used IF you have one FormEditor per form. I currently don't + //this can only be used IF you have one FormEditor per form. I currently don't end; Procedure TCustomFormEditor.ClearSelected; Begin -FSelectedComponents.Clear; + FSelectedComponents.Clear; end; diff --git a/ide/main.pp b/ide/main.pp index 5096ef0ebb..40d73acab6 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -1634,6 +1634,7 @@ Begin ObjectInspector1.FillComponentComboBox; TDesigner(TForm(NewCI.Control.Owner).Designer).AddControlCode(NewCI.Control); + if NewCI.Control is TControl then begin // set the OnMouseDown and OnMouseUp event so we know when the control // is selected or a new control is dropped @@ -1648,68 +1649,8 @@ writeln('NewComponent is TControl'); MouseDownControl:=nil; ControlClick(Notebook1); //this resets it to the mouse. -exit; -//see if the mouse moved or there was simply a click on the form -{ if (X >= 0) and (X <= TControl(sender).Width) and - (Y >= 0) and (Y <= TControl(sender).Height) then - begin - // mouse was down and up on the form. - // We clicked on the form. Let's see what the active selection is in the - // IDE control bar. If it's the pointer, then we set the - // FormEditor1.SelectedComponents to Sender, - // otherwise we drop a control and call the CreateComponent function. - if BPressed = 1 then - Begin // mouse pointer button pressed. - FormEditor1.ClearSelected; - Writeln('Clicked on the form!!!!! Forms name is '+TForm(Sender).Name); - FormEditor1.AddSelected(TComponent(Sender)); - end - else - Begin - // add a new control - - // check to see if the mouse moved between clicks. - // If so then they sized the control - if (MouseUpPos.X <> MouseDownPos.X) or (MouseUpPos.Y <> MouseDownPos.Y) then begin - - // CInterface := TComponentInterface(FormEditor1.CreateComponent(nil, - // TComponentClass(TIdeComponent( - // ideComplist.items[bpressed-1]).ClassType) - // ,NewLeft1,NewTop1,NewLeft2,NewTop2)); - end - else begin - - end; - - CInterface := TComponentInterface(FormEditor1.CreateComponent(nil, - TComponentClass(TIdeComponent( - ideComplist.items[bpressed-1]).ClassType), - MouseDownPos.X,MouseDownPos.Y,-1,-1)); - - //Set up some default values for the control here - // CInterface is a TComponentInterface defined in CustomFormEditor.pp - CInterface.SetPropByName('VISIBLE',True); -// CInterface.SetPropByName('NAME','PLEASEWORK1'); -// CInterface.SetPropbyName('CAPTION','Click me!'); - CInterface.SetPropByName('HINT','Click'); - CInterface.SetPropByName('TOP',10); - CInterface.SetPropByName('ONCLICK',@ClickOnControl); - - //set the ONCLICK event so we know when the control is selected; -// TControl(CInterface.Control).OnClick := @ClickOnControl; - FormEditor1.ClearSelected; - FormEditor1.AddSelected(TComponent(Cinterface.Control)); - end; -//TIdeComponent(ideComplist.items[bpressed-1]). - - end; - ControlClick(Notebook1); //this resets it to the mouse. -} -Writeln('MouseuponControl'); end; - - {------------------------------------------------------------------------------} procedure TForm1.mnuNewFormClicked(Sender : TObject); var @@ -2319,9 +2260,9 @@ end. { ============================================================================= $Log$ - Revision 1.17 2000/12/15 15:29:09 lazarus - Changes my Mattias for dropping controls. - Changes by Shane for adding code to the form source. + Revision 1.18 2000/12/15 18:25:16 lazarus + Changes from Mattias and I. + Shane Revision 1.16 2000/12/01 20:23:34 lazarus renamed Object_Inspector and Prop_edits by removing the underline.