Solved

Problem setting StringGrid Color

Posted on 1997-04-08
7
368 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

20 Experts available now in Live!

Get 1:1 Help Now