Change Color in Text

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
bars_12
Posts: 3
Joined: 01 Mar 2011, 23:13

Change Color in Text

Post by bars_12 » 01 Mar 2011, 23:51

Hello!
I try changing a color in the text in DXF file direct in the Demo Editor from VCL Import CAD Components (only as example)


This code it's work

Code: Select all

procedure TfmPreview.FillImage(ASManager: TsgSelectionManager;
  ADXFImage: TsgCADImage);
var
  I: Integer;
  vEnt: TsgDXFEntity;
  vDXFImage: TsgCADImage;
begin
  FSManager := ASManager;
  vDXFImage := TsgCADImage.Create;
  for I := 0 to FSManager.SelectedEntities.Count - 1 do
  begin
    vEnt := TsgDXFEntityClass(TsgDXFEntity(FSManager.SelectedEntities[I]).ClassType).Create;
    vEnt.AssignEntity(TsgDXFEntity(FSManager.SelectedEntities[I]));
    vDXFImage.Converter.OnCreate(vEnt);
    vDXFImage.Converter.Sections[csEntities].AddEntity(vEnt);
    vDXFImage.Converter.Loads(vEnt);
    if vEnt is TsgDXFText then
    begin
      showmessage('Das ist ein Text'+IntToStr(vEnt.Color and $FFFFFFFF));
      vEnt.SetColor($00120092); // die Farbe soll man gerade in Text-Entyti weckseln
      vDXFImage.Converter.loads(vEnt); // und dann bei TsgCADImage dass hat als ein Kind das Entity speichern
      showmessage(IntToStr(vEnt.Color and $FFFFFFFF));
    end;
  end;
  vDXFImage.GetExtents;
  FDNavigator.Picture.Graphic := vDXFImage;
  FDNavigator.Color := vDXFImage.BackgroundColor;
  //TsgCADImage(sgImage.Picture.Graphic).IsWithoutBorder := True;// without border
  vDXFImage.Free;
  FDNavigator.FitToSize;
end;

But in commonpicture it's do not worked

Code: Select all

var
  CurNav : TsgCADImage;
  curEnt: TsgDXFEntity; //  das Objekt, das werden wir verfarben
begin
    CurNav := TsgDXFImage(FDNavigator.Picture.Graphic); // Hier converten wir unser Navigator-Objekt in Visualobjekt, mit dem kцnnen wir arbeiten als Array von Entytis
  curEnt := TsgDXFEntityClass(TsgDXFEntity(Fmanager.SelectedEntities[0]).ClassType).Create;
  if curEnt is TsgDXFText then
  begin
      curEnt.SetColor($0088EA92); // die Farbe soll man gerade in Text-Entyti weckseln#
    CurNav.Converter.loads(curEnt); // und dann bei TsgCADImage dass hat als ein Kind das Entity speichern
   // CurNav.GetExtents;

    FDNavigator.Picture.Graphic := CurNav;
   // DNavigator.Refresh;
    ShowMessage('Der Font vom Text ist getauscht!');
  end;
I think that a problem FDNavigator.Picture.Graphic := CurNav; And it's very intrested, that have I a problem with memory - the messege Access violation after
CurNav.free in the and of procedure.
But when make I no free, then have I a message access violation whet I second select making

bars_12
Posts: 3
Joined: 01 Mar 2011, 23:13

Re: Change Color in Text

Post by bars_12 » 02 Mar 2011, 00:00

Platform XP and Delphi 2006

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Change Color in Text

Post by support » 02 Mar 2011, 18:54

Hello.
The second snippet doesn't work because you change color of the entity that doesn't belongs to TsgCADImage:

Code: Select all

...
  curEnt := TsgDXFEntityClass(TsgDXFEntity(Fmanager.SelectedEntities[0]).ClassType).Create;
  if curEnt is TsgDXFText then
  begin
      curEnt.SetColor($0088EA92);
...
This creates new entity that doesn't contained in Convertor. In first snippet you add created entity to Converter.

Code: Select all

TsgDXFEntity(Fmanager.SelectedEntities[0]).SetColor($0088EA92);
will affect entity's color.

Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply