Hello all

I want to query a dataset and then represent the nature or state of that data 
by one of three different colours (essentially red if a field contains data in 
all rows, amber if a field contains data in some rows but not others, and green 
if a field contains data in none of the rows).

The following code shows what I did in a rough and ready solution using the 
OnDrawCell of a TStringGrid, which is not a workable solution since the process 
starts from scratch each time the Grid is repainted (so, for example, if you 
return to the Grid's form after focusing on another application).
 There will be, of course, many ways of achieving the objective, but what might 
be the most efficient (using any components - Grid does not have to feature) ?

Thanks for any suggestions

Regards
Steve
 
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

procedure TOverviewForm.SGDrawCell(Sender: TObject; ACol, ARow: Integer;Rect: 
TRect; State: TGridDrawState);
var i, j, count: Byte;  colour: TColor;  theDate: TDateTime;
begin
for j:= 1 to max do
 begin
  theDate:= StrToDateTime(inttostr(j) + '/' + inttostr(mnth) + '/' + yr);
  getData(theDate); // Gets data for a single day
  for i:= 2 to Q_Overview.FieldCount-1 do
   begin
    Q_Overview.First;
    count:=0;
    while not Q_Overview.Eof do    // Iterates over each column in turn and 
counts the cells containing data
      begin
       if  Q_Overview.Fields[i].AsString > '' then
         inc(count);
       Q_Overview.Next;
      end;
    if count > 0 then                   // Sets variable colour according to 
value of variable count
     begin
       if count = 27 then
        colour:= $001111FF
       else
        colour:= $001BBFF
     end
    else
      colour:= $0044DE44;
    if (ACol = i-1) and (ARow = j)  then
     begin
      SG.Canvas.Brush.Color := colour;
      SG.Canvas.FillRect(Rect);
     end;
   end;
 end;
end;



procedure TOverviewForm.Button1Click(Sender: TObject);
var i: Byte;
begin
//starttime:= gettickcount;
mnth:= cb_Month.ItemIndex+1;
yr:= cb_Year.Text;
 case mnth of
  1,3,5,7,8,10,12: max:= 31;
  4,6,9,11: max:= 30;
  2: if isLeapYear(strtoint(yr)) then max:= 29 else max:= 28;
 end;

for i:= 1 to max do
 SG.Cells[0,i]:= FormatDateTime('ddd  d',StrToDateTime(inttostr(i) + '/' + 
inttostr(mnth) + '/' + yr));
SG.Repaint;         // have grid repaint itself
{endtime:= gettickcount;
secondstaken:= (endtime-starttime)/1000;
showmessage('Time taken = ' + floattostr(secondstaken) + ' secs'); }   // Takes 
about 45 secs from start to finish with 14 data fields and 28 - 31 rows 
end;

***************************************************************************
This e-mail and any files transmitted with it are confidential. If you are not 
the intended recipient, any reading, printing, storage, disclosure, copying or 
any other action taken in respect of this e-mail is prohibited and may be 
unlawful. If you are not the intended recipient, please notify the sender 
immediately by using the reply function and then permanently delete what you 
have received.
Content of emails received by this Trust will be subject to disclosure under 
the Freedom of Information Act 2000, subject to the specified exemptions, 
including the Data Protection Act 1998 and Caldicott Guardian principles.
This footnote also confirms that this email message has been swept by 
MIMESweeper and Sophos Anti-virus for the presence of computer viruses.
***************************************************************************



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Great things are happening at Yahoo! Groups.  See the new email design.
http://us.click.yahoo.com/SktRrD/hOaOAA/yQLSAA/i7folB/TM
--------------------------------------------------------------------~-> 

-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to