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

    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
Alpha_AIAsked:
Who is Participating?
 
TheRealLokiConnect With a Mentor Senior DeveloperCommented:
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
 
SteveBayCommented:
You may wish to check the ParentColor or the ParentFont Properties on the cxTreeList. If they are True try setting them to False.
0
 
TheRealLokiSenior DeveloperCommented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Alpha_AIAuthor Commented:
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
 
Alpha_AIAuthor Commented:
I know if this is the best way to parse through files but its the only way i know how.

Ben
0
 
Alpha_AIAuthor Commented:
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
 
Alpha_AIAuthor Commented:
SteveBay,

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

Ben
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.