Solved

I am using cxTreelist from DevXpress and am trying to set the ParentNode.Values[6] to a TColor.

Posted on 2007-11-28
9
1,700 Views
Last Modified: 2013-11-22
    ColorString := ScanForColor(RichEdit10.Lines.Text,ParentNode.Values[2]);
     ColorString := '$'+ColorString;
     TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn5.Properties).DefaultColor := HexToTColor(ColorString);
     TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn5.Properties).DefaultDescription := 'Ben';
     ParentNode.Values[6] := TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn5.Properties).DefaultColor;

Hellop,

I am trying to set the ParentNode.Values[6] to which ever color is in the ColorString
ColorString is like this $303030;
and HexToTColor converts $303030 to a TColor however i cannot apply it to the current node in the cxTreelist.

Anyone knows?

Ben
0
Comment
Question by:Alpha_AI
9 Comments
 
LVL 14

Expert Comment

by:SteveBay
Comment Utility
You may wish to check the ParentColor or the ParentFont Properties on the cxTreeList. If they are True try setting them to False.
0
 
LVL 17

Expert Comment

by:TheRealLoki
Comment Utility
I've got DevExpress here, but I haven't used the TcxColorCombobox or TxcTreeList very often.
Can you post a bit more of your code so i can see where this code is being run.
1 thing off the top of my head is Styles - are you using any styles? eg. cxTreeList11.Sytles.Content, and are they overriding your colours?
0
 

Author Comment

by:Alpha_AI
Comment Utility
TheRealLoki,

Im not using styles at all,

Here is my code. Basically it reads every div id code there is and looks for the css assigned to that id
it then retrieves the color off the id from the css and is supposed to be written to the node.values[6]

var
  i : integer;
  ParentNode : TcxTreeListNode;
  ChildNode: TcxTreeListNode;
  HTMLNode : TcxTreeListNode;
  DIVNode : TcxTreeListNode;
  LinkSkipMode : boolean;
  PHPSkipMode : boolean;
  Pos1 : integer;
  Pos2 : integer;
  Pos3 : integer;
  DIVArray : Array [0..10] of TcxTreeListNode;
  a : integer;
  BeenThereDoneThat : boolean;
  ColorString : string;
begin
    if AnsiContainsStr(RichEdit1.Lines.Strings[i],'<div id') = true then
    begin
    if BeenThereDoneThat = true then
      begin
     // inc(a,1);
      end;
    DIVNode := ParentNode;
    Pos1 := 0;
    Pos2 := 0;
    Pos1 := PosEx('"',RichEdit1.Lines.Strings[i],1);
    inc(Pos1,1);
    Pos2 := PosEx('"',RichEdit1.Lines.Strings[i],Pos1+1);

    ParentNode := cxTreelist11.AddChild(ParentNode);
    ParentNode.Values[0] := AnsiMidStr(RichEdit1.Lines.Strings[i], Pos1, Pos2-Pos1);
    ParentNode.Values[2] := AnsiMidStr(RichEdit1.Lines.Strings[i], Pos1, Pos2-Pos1);
 //   ParentNode.Values[6] := clBlue;//'#'+ScanForColor(RichEdit10.Lines.Text,ParentNode.Values[2]);

     //ColorBox2.Color := HexToTColor(+'''');
     if ScanForColor(RichEdit10.Lines.Text,ParentNode.Values[2]) <> '' then
     begin
     ColorString := ScanForColor(RichEdit10.Lines.Text,ParentNode.Values[2]);
     ColorString := '$'+ColorString;
     TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn5.Properties).DefaultColor := HexToTColor(ColorString);
     TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn5.Properties).DefaultDescription := 'Ben';
     ParentNode.Values[6] := TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn5.Properties).DefaultColor;
     end;
 //    TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn5.Properties).DefaultColor := HexToTColor('$'+ScanForColor(RichEdit10.Lines.Text,ParentNode.Values[2])+'''');
 //    TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn5.Properties).DefaultDescription := '';
     //.Items.Items[0].Color := clBlue;//'#'+ScanForColor(RichEdit10.Lines.Text,ParentNode.Values[2];
 //   ParentNode.Values[6] := TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn5.Properties).Items.Ite.Items[0].Color;
    ParentNode.Values[3] := 'div';
    ParentNode.Values[4] := 'Section';
    DIVArray[a] :=  ParentNode;
    inc(a,1);
    ParentNode.MakeVisible;
    ParentNode.Focused := True;
    end;

This is the scanforcolor code:

function TForm1.ScanForColor(Text, TagID: string): string;
var
  i : integer;
  j: integer;
    ANode: TcxTreeListNode;
    NodeIndex : integer;
    RichEditIndex : integer;
    HexCode : string;
    PosIndex : integer;
    SpaceCharIndex1 : integer;
    SpaceCharIndex2 : integer;
    Count : integer;
begin
PosIndex := 0;
    if RichEdit10.Lines.Text <> '' then
     begin
    for i := 0 to RichEdit10.Lines.Count-1 do
    begin
     if RichEdit10.Lines.Strings[i] = '#'+TagID+'{' then
      begin
      j := i;
      while RichEdit10.Lines.Strings[j+1] <> '}' do
       begin
       if AnsiContainsStr(RichEdit10.Lines.Strings[j+1],'background') then
       begin

       PosIndex := Pos('background-color:#',RichEdit10.Lines.Strings[j+1]);
       Count := 18;

       if PosIndex = 0 then
       begin
       PosIndex := Pos('background:#',RichEdit10.Lines.Strings[j+1]);
       Count := 12;
       end;

       PosIndex := PosIndex + Count;
       //locate hex which are only three digits long
       SpaceCharIndex1 := PosEx(' ',RichEdit10.Lines.Strings[j+1],PosIndex);
       //locate hex which is six digits long
       SpaceCharIndex2 := PosEx(';',richEdit10.Lines.Strings[j+1],PosIndex);
       If SpaceCharIndex1 < SpaceCharIndex2 then
        begin
        HexCode := AnsiMidStr(RichEdit10.Lines.Strings[j+1],PosIndex,SpaceCharIndex1 - PosIndex);
        if HexCode = 'fff' then
         begin
         HexCode := 'ffffff';
         end;
        break;
        end
       else
        begin
        HexCode := AnsiMidStr(RichEdit10.Lines.Strings[j+1],PosIndex,SpaceCharIndex2 - PosIndex);
      //  Result := HextoTColor(Hexcode);
        break;
        end;


        end;
       inc(j,1);
       end;
      end;
      Result := HexCode;
     end;
     end;
end;

and here is there HexToTColor function

function TForm1.HexToTColor(sColor: string): TColor;
begin
  Result := StringToColor('$' + Copy(sColor, 6, 2) + Copy(sColor, 4, 2) + Copy(sColor, 2, 2));
end;

0
 

Author Comment

by:Alpha_AI
Comment Utility
I know if this is the best way to parse through files but its the only way i know how.

Ben
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Alpha_AI
Comment Utility
i meant 'i dont know if this is the best way to parse through files but its the only way i know how.

Ben
0
 

Author Comment

by:Alpha_AI
Comment Utility
SteveBay,

Ive also try setting the parentcolor to false and that doesnt work.

Ben
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 125 total points
Comment Utility
ok, I had a bit of a play around and got things working how I think you want it

(note, this code does not match with yours but it works on a simple demo - you just need to plug it into your logic)

procedure TForm1.cxColorComboBox1PropertiesChange(Sender: TObject);
begin
  if assigned(cxTreeList11.FocusedNode) then
    cxTreeList11.FocusedNode.Values[1] := cxColorComboBox1.ColorValue;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ColorString: string;
  ParentNode: TcxTreelistNode;
  thiscolor: TColor;
  thisDescription: string;
begin
// Make sure you have this property set to cxncNone or you will see 48.48.48 instead of "Ben"
  TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn2.Properties).NamingConvention := cxncNone;


  ColorString := '00303030'; //ScanForColor(RichEdit10.Lines.Text,ParentNode.Values[2]);
  ColorString := '$'+ColorString;
  thiscolor := StringToColor(ColorString);
  thisDescription := 'Ben';

  ParentNode := cxTreelist11.AddChild(nil);
  ParentNode.Values[0] := 'test';
  ParentNode.Values[1] := thisdescription;

// check if this is a new color, and set the default

  with TcxColorComboBoxProperties(cxTreeList11cxTreeListColumn2.Properties) do
  begin
    if Items.GetIndexByColor(thiscolor) = -1 then // this is a new color, add it
      Items.AddColor( thiscolor, thisDescription);

    DefaultColor := thiscolor;
    DefaultDescription := thisDescription;
  end;
end;

also, I think you need to set
  ParentNode := nil;
before this line somewhere
  ParentNode := cxTreelist11.AddChild(ParentNode);

otherwise ParentNode is undefined..and bad stuff could happen
0
 
LVL 1

Expert Comment

by:Computer101
Comment Utility
Forced accept.

Computer101
EE Admin
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now