home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / DBEDITCH.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  5.6 KB  |  201 lines

  1. {**********************************************}
  2. {  TCustomDBChart (or derived) Editor Dialog   }
  3. {  Copyright (c) 1995-1998 by David Berneda    }
  4. {  All Rights Reserved                         }
  5. {**********************************************}
  6. {$I teedefs.inc}
  7. unit DBEditCh;
  8.  
  9. interface
  10.  
  11. Uses {$IFDEF D1}IEdit16{$ELSE}IEditCha,IEdiSeri{$ENDIF};
  12.  
  13. {$IFNDEF D1}
  14. Var InternalOnGetDesignerNames:TOnGetDesignerNamesEvent;
  15. {$ENDIF}
  16.  
  17. implementation
  18.  
  19. uses
  20.   WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls,
  21.   Dialogs, DB, DBTables, StdCtrls, Teengine, TeeConst, Chart, DBChart,
  22.   TeeProcs;
  23.  
  24. {$IFNDEF D1}
  25. Function OnDBChartGetSourceStyle(ASeries:TChartSeries):TTeeDataSourceStyle;
  26. begin
  27.   result:=dsStyle_NoData;
  28.   if Assigned(ASeries.DataSource) then
  29.      if ASeries.DataSource is TDataSet then result:=dsStyle_Dataset
  30.                                        else
  31.      if ASeries.DataSource is TDataSource then result:=dsStyle_Datasource;
  32. end;
  33. {$ENDIF}
  34.  
  35. Procedure OnDBChartFillFields( AForm:{$IFDEF D1}TChartEditForm{$ELSE}TFormTeeSeries{$ENDIF}); far;
  36. Var tmpList : TStrings;
  37.     tmp     : TComponent;
  38.  
  39.   Procedure AddField(Const tmpSt:String; tmpType:TFieldType);
  40.   Var tt:Longint;
  41.   begin
  42.     With AForm do
  43.     Case tmpType of
  44.       ftSmallint,
  45.       ftInteger,
  46.       ftWord,
  47.       ftFloat,
  48.       ftCurrency,
  49.       ftBCD,
  50.       ftDate,
  51.       ftTime,
  52.       ftDateTime: begin
  53.                     tmpList.Add(tmpSt);
  54.                     if tmp is TDataSet then
  55.                     for tt:=0 to TheSeries.ValuesLists.Count-1 do
  56.                         GetSourceCombo(tt).Items.Add(tmpSt);
  57.                   end;
  58.       ftString: if tmp is TDataSet then tmpList.Add(tmpSt);
  59.     end;
  60.   end;
  61.  
  62. Var t       : Longint;
  63.     tmpData : TDataSet;
  64.     tmpSt   : String;
  65.     tmpField: String;
  66. Begin
  67.   With AForm do
  68.   begin
  69.     tmp:=GetSelectedSource;
  70.     if Assigned(TheSeries) and
  71.        Assigned(tmp) then
  72.     begin
  73.       tmpData:=nil;
  74.       if (tmp is TDataSet) then
  75.       begin
  76.         tmpData:=TDataSet(tmp);
  77.         tmpList:=CBLabelsField.Items;
  78.       end
  79.       {$IFNDEF D1}
  80.       else
  81.       if (tmp is TDataSource) then
  82.       begin
  83.         tmpData:=TDataSource(tmp).DataSet;
  84.         tmpList:=LBAvailFields.Items;
  85.       end
  86.       {$ENDIF};
  87.       tmpList.Clear;
  88.       if Assigned(tmpData) then
  89.       With tmpData do
  90.       begin
  91.         if FieldCount>0 then
  92.            for t:=0 to FieldCount-1 do
  93.                AddField(Fields[t].FieldName,Fields[t].DataType)
  94.         else
  95.         begin
  96.           FieldDefs.Update;
  97.           for t:=0 to FieldDefs.Count-1 do
  98.               AddField(FieldDefs[t].Name,FieldDefs[t].DataType);
  99.         end;
  100.       end;
  101.       {$IFNDEF D1}
  102.       if (tmp is TDataSource) then
  103.       begin
  104.         tmpSt:=TheSeries.MandatoryValueList.ValueSource;
  105.         LBSelFields.Clear;
  106.         for t:=1 to TeeNumFields(tmpSt) do
  107.         begin
  108.           tmpField:=TeeExtractField(tmpSt,t);
  109.           LBSelFields.Items.Add(tmpField);
  110.           With LBAvailFields.Items do Delete(IndexOf(tmpField));
  111.         end;
  112.       end;
  113.       {$ENDIF}
  114.     end;
  115.   end;
  116. end;
  117.  
  118. Procedure OnDBChartIsDateTimeSource( AComponent:TComponent;
  119.                                      Const ValueSource:String;
  120.                                      Var IsDateTime:Boolean); far;
  121. var tmpField:TField;
  122. begin
  123.   IsDateTime:=False;
  124.   if AComponent is TDataSet then
  125.   begin
  126.     tmpField:=TDataSet(AComponent).FindField(ValueSource);
  127.     if Assigned(tmpField) then
  128.     Case tmpField.DataType of
  129.       ftDate,ftTime,ftDateTime: IsDateTime:=True;
  130.     end;
  131.   end;
  132. end;
  133.  
  134. Function OnDBChartIsValidComponentSource( AComponent:TComponent
  135.                                           {$IFNDEF D1}
  136.                                           ; DataSourceStyle:TTeeDataSourceStyle
  137.                                           {$ENDIF}):Boolean; far;
  138. begin
  139.   result:={$IFNDEF D1}((DataSourceStyle=dsStyle_DataSet) and{$ENDIF} (AComponent is TDataSet)
  140. {$IFNDEF D1}
  141.    )
  142.     or
  143.     ((DataSourceStyle=dsStyle_DataSource) and (AComponent is TDataSource))
  144. {$ENDIF}
  145.     ;
  146. end;
  147.  
  148. Procedure OnCreateEditDBChart(AForm:{$IFDEF D1}TChartEditForm{$ELSE}TFormTeeSeries{$ENDIF}; AChart:TCustomChart); far;
  149. var tmp:Integer;
  150. begin
  151.   With AForm do
  152.   begin
  153.     if AChart is TCustomDBChart then
  154.     begin
  155.       With CBDataSourceStyle.Items do
  156.       begin
  157.         if IndexOf(TeeMsg_DataSet)=-1 then Add(TeeMsg_Dataset);
  158.         {$IFNDEF D1}
  159.         if IndexOf(TeeMsg_SingleRecord)=-1 then Add(TeeMsg_SingleRecord);
  160.         {$ENDIF}
  161.       end;
  162.       OnChartFillFields:=OnDBChartFillFields;
  163.       {$IFNDEF D1}
  164.       OnChartGetSourceStyle:=OnDBChartGetSourceStyle;
  165.       {$ENDIF}
  166.       OnChartIsValidComponentSource:=OnDBChartIsValidComponentSource;
  167.       OnChartIsDateTimeSource:=OnDBChartIsDateTimeSource;
  168.       {$IFNDEF D1}
  169.       if Assigned(InternalOnGetDesignerNames) then
  170.          OnGetDesignerNames:=InternalOnGetDesignerNames;
  171.       {$ENDIF}
  172.     end
  173.     else
  174.     begin
  175.       With CBDataSourceStyle.Items do
  176.       begin
  177.         tmp:=IndexOf(TeeMsg_DataSet);
  178.         if tmp<>-1 then Delete(tmp);
  179.         tmp:=IndexOf(TeeMsg_SingleRecord);
  180.         if tmp<>-1 then Delete(tmp);
  181.       end;
  182.       OnChartFillFields:=nil;
  183.       {$IFNDEF D1}
  184.       OnChartGetSourceStyle:=nil;
  185.       {$ENDIF}
  186.       OnChartIsValidComponentSource:=nil;
  187.       OnChartIsDateTimeSource:=nil;
  188.       {$IFNDEF D1}
  189.       OnGetDesignerNames:=nil;
  190.       {$ENDIF}
  191.     end;
  192.   end;
  193. end;
  194.  
  195. initialization
  196. {$IFNDEF D1}
  197.   InternalOnGetDesignerNames:=nil;
  198. {$ENDIF}
  199.   InternalOnCreateEditSeries:=OnCreateEditDBChart;
  200. end.
  201.