?
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
Medium Priority
?
1,904 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
8 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 20366344
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
ID: 20370379
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
ID: 20372417
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Alpha_AI
ID: 20372420
I 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
ID: 20372422
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
ID: 20372426
SteveBay,

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

Ben
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 20378176
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
ID: 21216653
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses

809 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