Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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,743 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 125 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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