Solved

Problem setting StringGrid Color

Posted on 1997-04-08
7
377 Views
Last Modified: 2012-05-04
I'm having a prboblem setting StringGrid's color to anything but one of the solid system colors, clAqua thru clYellow.  My  video is set for 256 colors and works fine.
There is no problem setting all 256 colors in other components including DrawGrid and DBGrid. What's different about the StringGrid component? Does it use a different pallette or limit the system  pallette?

I'm attempting to use the color dialog to set the color. It should work since its color property is of type TColor which is the same as stringgrid's color property. (When I set my video driver to 16-bit color, stringgrid color work ok).

Thanks,
Jerry G.
0
Comment
Question by:jgrant101
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:javiertb
ID: 1335247
How do you select your DBGrid among 256 colors?
0
 

Author Comment

by:jgrant101
ID: 1335248
Edited text of question
0
 

Author Comment

by:jgrant101
ID: 1335249
javiertb,
You asked how I change the DBGrid's color to one of 256. (Admittedly, I did not check all 256 colors).I use a color dialog control and select a color which I then use to set the DBGrid's color property.  It seems that the stringgrid control either uses a different pallette or limits the system pallette.

Thanks for your help
Jerry G.
0
Independent Software Vendors: 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!

 
LVL 2

Accepted Solution

by:
javiertb earned 100 total points
ID: 1335250
If you want to get 256 colors to chose from for your component, you'll have to deal with the API functions related to palette creation, manipulation and so on.
0
 

Author Comment

by:jgrant101
ID: 1335251
"If you want to get 256 colors to chose from for your component, you'll have to deal with the API functions related to palette creation, manipulation and so on."

I don't agree with this. Why can I set the color of a DBGrid or a DrawGrid to pastel yellow (color := $A8FFFF) for example, but not the StringGrid?  What's different about the stringgrid? I looked at the VCL souce code but could not find the difference.

Thanks for your help,
Jerry G.
0
 
LVL 2

Expert Comment

by:javiertb
ID: 1335252
Here you have the answer, hope this help:

TCustomGrid defines the FixedColor property and assumes that any code draws the fixed areas will use this propery. TDrawGrid and TStringGrid does this. However, TDBGrid (TCustomDBGrid, actually) defines another property called TitleColor and uses this when drawing. Unfortunately this property is defined as protected making it unavailable for component users at both design and run-time.

The solution is to derive your own component and use this instead of TDBGrid.The following unit does this:


unit Dbgridfx;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, Grids, DBGrids;

type
  TDBGridFix = class(TDBGrid)
  private
    { Private declarations }
    procedure SetFixedFixedColor(Value: TColor);
    function  GetFixedFixedColor: TColor;
  published
    { Published declarations }
    property FixedColor: TColor read GetFixedFixedColor write SetFixedFixedColor default clBtnFace;
  end;

procedure Register;

implementation

procedure TDBGridFix.SetFixedFixedColor(Value: TColor);
begin
  inherited TitleColor := Value;
  inherited FixedColor := Value; { Not really needed, just to be on the safe side }
end;

function TDBGridFix.GetFixedFixedColor: TColor;
begin
  Result := inherited TitleColor;
end;

procedure Register;
begin
  RegisterComponents('Data Access', [TDBGridFix]);
end;

end.

Regards,
Javi
0
 

Author Comment

by:jgrant101
ID: 1335253
You are missing my point. I'm having trouble setting StringGrid's colors. DBGrid and DrawGrid colors can be set as expected.  Your response was to create a new component based on TDBGrid.

Moreover, the problem exists with any row or cell, not just the fixed areas.

Any other suggestions?


0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to center only a line in richedit? 4 69
Firemonkey allowing RTL on android 6 56
Microsoft Access 97 and Delphi XE2 9 71
firemonkey Android Listview Sort items 7 70
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

680 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