📄 jvdataprovidereditors.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvDataProviderPropEdits.pas, released on --.
The Initial Developer of the Original Code is Marcel Bestebroer
Portions created by Marcel Bestebroer are Copyright (C) 2002 - 2003 Marcel
Bestebroer
All Rights Reserved.
Contributor(s):
Peter Th鰎nqvist
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvDataProviderEditors.pas,v 1.25 2005/01/29 06:36:55 marquardt Exp $
unit JvDataProviderEditors;
{$I jvcl.inc}
interface
uses
Classes,
{$IFDEF COMPILER6_UP}
DesignIntf, DesignEditors, DesignMenus,
{$ELSE}
DsgnIntf, Menus,
{$ENDIF COMPILER6_UP}
JvDataProvider, JvDataProviderIntf;
type
{$IFDEF COMPILER6_UP}
TGetPropEditProc = TGetPropProc;
{$ENDIF COMPILER6_UP}
TJvDataConsumerExtPropertyEditor = class(TPropertyEditor)
protected
function GetConsumerExt: TJvDataConsumerAggregatedObject;
function GetConsumer: IJvDataConsumer;
function GetConsumerImpl: TJvDataConsumer;
end;
TJvProviderEditor = class(TDefaultEditor)
protected
function Provider: IJvDataProvider;
public
procedure Edit; override;
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
{$IFDEF COMPILER6_UP}
procedure PrepareItem(Index: Integer; const AItem: IMenuItem); override;
{$ELSE}
procedure PrepareItem(Index: Integer; const AItem: TMenuItem); override;
{$ENDIF COMPILER6_UP}
end;
TJvDataConsumerProperty = class(TEnumProperty)
private
FOrgStrProc: TGetStrProc;
procedure CheckAndAddComp(const S: string);
protected
function GetConsumerServiceAt(Index: Integer): TJvDataConsumer;
function GetProviderIntfAt(Index: Integer): IJvDataProvider; dynamic;
procedure SetProviderIntfAt(Index: Integer; Value: IJvDataProvider); dynamic;
function GetProviderIntf: IJvDataProvider;
procedure SetProviderIntf(Value: IJvDataProvider);
procedure GetExtensionsProperties(ConsumerSvc: TJvDataConsumer; Proc: TGetPropEditProc);
procedure GetExtensionProperties(ConsumerSvcExt: TJvDataConsumerAggregatedObject; Proc: TGetPropEditProc);
public
function AllEqual: Boolean; override;
function GetAttributes: TPropertyAttributes; override;
procedure GetProperties(Proc: TGetPropEditProc); override;
function GetValue: string; override;
procedure SetValue(const Value: string); override;
procedure GetValues(Proc: TGetStrProc); override;
end;
TJvDataProviderTreeProperty = class(TEnumProperty)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
procedure SetValue(const Value: string); override;
end;
TJvDataProviderItemIDProperty = class(TJvDataConsumerExtPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
procedure SetValue(const Value: string); override;
end;
TJvDataConsumerContextProperty = class(TJvDataConsumerExtPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
procedure SetValue(const Value: string); override;
end;
TJvConsumerNotifyComponentProperty = class(TComponentProperty)
protected
EnumProc: TGetStrProc;
function IsValidComp(AComponent: TComponent): Boolean;
procedure CheckAndAddComp(const S: string);
public
procedure GetValues(Proc: TGetStrProc); override;
end;
implementation
uses
SysUtils, TypInfo,
{$IFDEF HAS_UNIT_RTLCONSTS}
RTLConsts,
{$ELSE}
Consts,
{$ENDIF HAS_UNIT_RTLCONSTS}
JvDataConsumerContextSelectForm, JvDataConsumerItemSelectForm,
JvDataProviderDesignerForm, JvDataContextManagerForm, JvDsgnConsts;
type
TOpenSvc = class(TJvDataConsumer);
TOpenConsumerAggregate = class(TJvDataConsumerAggregatedObject);
//=== { TJvDataConsumerExtPropertyEditor } ===================================
function TJvDataConsumerExtPropertyEditor.GetConsumerExt: TJvDataConsumerAggregatedObject;
begin
Result := TJvDataConsumerAggregatedObject(GetComponent(0));
end;
function TJvDataConsumerExtPropertyEditor.GetConsumer: IJvDataConsumer;
begin
Result := GetConsumerImpl;
end;
function TJvDataConsumerExtPropertyEditor.GetConsumerImpl: TJvDataConsumer;
begin
Result := TOpenConsumerAggregate(GetConsumerExt).ConsumerImpl;
end;
//=== { TJvDataConsumerProperty } ============================================
procedure TJvDataConsumerProperty.CheckAndAddComp(const S: string);
var
Comp: TComponent;
Prov: IJvDataProvider;
Ref: IUnknown;
begin
if Assigned(FOrgStrProc) then
begin
Comp := Designer.GetComponent(S);
if Comp <> nil then
with Comp do
if GetInterface(IInterfaceComponentReference, Ref) and GetInterface(IJvDataProvider, Prov) then
FOrgStrProc(S);
end;
end;
function TJvDataConsumerProperty.GetConsumerServiceAt(Index: Integer): TJvDataConsumer;
begin
Result := TJvDataConsumer(GetOrdValueAt(Index));
end;
function TJvDataConsumerProperty.GetProviderIntfAt(Index: Integer): IJvDataProvider;
var
Svc: TJvDataConsumer;
begin
Svc := GetConsumerServiceAt(Index);
if Svc = nil then
Result := nil
else
Result := Svc.ProviderIntf;
end;
procedure TJvDataConsumerProperty.SetProviderIntfAt(Index: Integer; Value: IJvDataProvider);
var
Svc: TJvDataConsumer;
{$IFNDEF COMPILER6_UP}
CompRef: IInterfaceComponentReference;
ProvComp: TComponent;
{$ENDIF !COMPILER6_UP}
begin
Svc := GetConsumerServiceAt(Index);
if Svc <> nil then
begin
{$IFDEF COMPILER6_UP}
Svc.Provider := Value;
{$ELSE}
if Value <> nil then
begin
if not Supports(Value, IInterfaceComponentReference, CompRef) then
raise EPropertyError.CreateRes(@RsESpecifiedProviderIsNotATComponentDe);
ProvComp := CompRef.GetComponent;
end
else
ProvComp := nil;
Svc.Provider := ProvComp;
{$ENDIF COMPILER6_UP}
Modified;
end;
end;
function TJvDataConsumerProperty.GetProviderIntf: IJvDataProvider;
begin
Result := GetProviderIntfAt(0);
end;
procedure TJvDataConsumerProperty.SetProviderIntf(Value: IJvDataProvider);
var
I: Integer;
begin
for I := 0 to PropCount - 1 do
SetProviderIntfAt(I, Value);
end;
procedure TJvDataConsumerProperty.GetExtensionsProperties(ConsumerSvc: TJvDataConsumer;
Proc: TGetPropEditProc);
var
I: Integer;
begin
for I := 0 to TOpenSvc(ConsumerSvc).ExtensionCount - 1 do
GetExtensionProperties(TOpenSvc(ConsumerSvc).Extension(I), Proc);
end;
procedure TJvDataConsumerProperty.GetExtensionProperties(
ConsumerSvcExt: TJvDataConsumerAggregatedObject; Proc: TGetPropEditProc);
var
Components: IDesignerSelections;
begin
Components := CreateSelectionList;
{$IFDEF COMPILER6_UP}
Components.Add(ConsumerSvcExt);
GetComponentProperties(Components, tkAny, Designer, Proc);
{$ELSE}
Components.Add(MakeIPersistent(ConsumerSvcExt));
GetComponentProperties((Components as IComponentList).GetComponentList, tkAny, Designer, Proc);
{$ENDIF COMPILER6_UP}
end;
function TJvDataConsumerProperty.AllEqual: Boolean;
begin
Result := True;
end;
function TJvDataConsumerProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paSubProperties, paSortList
{$IFDEF COMPILER6_UP}, paVolatileSubproperties {$ENDIF}];
end;
procedure TJvDataConsumerProperty.GetProperties(Proc: TGetPropEditProc);
begin
GetExtensionsProperties(GetConsumerServiceAt(0), Proc);
end;
function TJvDataConsumerProperty.GetValue: string;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -