Subject RE: [IBO] Quoted Fields
Author Ondrej Kelle
> Also, we have to chage all tablenames in many components on all forms
>
> Are there any properties to help with this ? Any other ideas
> ? going thru
> that many forms is a mamoth job.

You could automate this process using a wizard. I wrote a template wizard
for you, see below.
The template as it is now does nothing, it just enumerates all open projects
and their modules, looking for instances of TIB_Query. In case you're
interested, you should write your code in ProcessIB_Query method to make it
actually do anything useful for you.
Hint: make sure to backup your projects prior to experimenting with this ;-)

HTH,
TOndrej

uses
Classes, SysUtils, ToolsApi, DsgnIntf, Windows, IB_Components;

type
TQuoteIBOWizard = class(TNotifierObject, IOTAWizard, IOTAMenuWizard)
private
procedure EnumModuleComponents(FormEditor: IOTAFormEditor);
procedure EnumProjectModules(Project: IOTAProject);
function ProcessIB_Query(IB_Query: TIB_Query): Boolean;
public
{ IOTANotifier }
procedure Destroyed;
{ IOTAWizard }
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
procedure Execute;
{ IOTAMenuWizard }
function GetMenuText: string;
end;

procedure Register;

implementation


procedure Register;
begin
RegisterPackageWizard(TQuoteIBOWizard.Create);
end;

function FindModuleInterface(AInterface: TGUID): IUnknown;
var
i: Integer;
begin
Result := nil;
with BorlandIDEServices as IOTAModuleServices do
for i := 0 to ModuleCount - 1 do
if (Modules[i].QueryInterface(AInterface, Result) = S_OK) then
Break;
end;

{ TQuoteIBOWizard private }

procedure TQuoteIBOWizard.EnumModuleComponents(FormEditor: IOTAFormEditor);
var
Root, Child: IOTAComponent;
I: Integer;
begin
Root := FormEditor.GetRootComponent;
if Assigned(Root) then
begin
for I := 0 to Root.GetComponentCount - 1 do
begin
Child := Root.GetComponent(I);
if Child.GetComponentType = 'TIB_Query' then
begin
if ProcessIB_Query(Child.GetComponentHandle) then
FormEditor.MarkModified;
end;
end;
end;
end;

procedure TQuoteIBOWizard.EnumProjectModules(Project: IOTAProject);
var
I, J: Integer;
ModuleInfo: IOTAModuleInfo;
Module: IOTAModule;
Editor: IOTAEditor;
FormEditor: IOTAFormEditor;
begin
for I := 0 to Project.GetModuleCount - 1 do
begin
ModuleInfo := Project.GetModule(I);
if Assigned(ModuleInfo) and (ModuleInfo.FormName <> '') then
begin
Module := ModuleInfo.OpenModule;
if Assigned(Module) then
begin
for J := 0 to Module.GetModuleFileCount - 1 do
begin
Editor := Module.GetModuleFileEditor(J);
if Assigned(Editor) and (Editor.QueryInterface(IOTAFormEditor,
FormEditor) = S_OK) then
EnumModuleComponents(FormEditor);
end;
end;
end;
end;
end;

function TQuoteIBOWizard.ProcessIB_Query(IB_Query: TIB_Query): Boolean;
begin
Result := False;
// quote/unquote fieldnames etc.
// set Result to True to mark current module as modified so it can be
saved
end;

{ TQuoteIBOWizard public }

procedure TQuoteIBOWizard.Destroyed;
begin
{ do nothing }
end;

procedure TQuoteIBOWizard.Execute;
var
ProjectGroup: IOTAProjectGroup;
Project: IOTAProject;
I: Integer;
begin
ProjectGroup := FindModuleInterface(IOTAProjectGroup) as IOTAProjectGroup;
if Assigned(ProjectGroup) then
begin
for I := 0 to ProjectGroup.ProjectCount - 1 do
EnumProjectModules(ProjectGroup.Projects[I]);
end
else
begin
Project := FindModuleInterface(IOTAProject) as IOTAProject;
if Assigned(Project) then
EnumProjectModules(Project)
else
raise Exception.Create('No project open');
end;
end;

function TQuoteIBOWizard.GetIDString: string;
begin
Result := 'TOndrej.TQuoteIBOWizard';
end;

function TQuoteIBOWizard.GetMenuText: string;
begin
Result := 'Quote IBO';
end;

function TQuoteIBOWizard.GetName: string;
begin
Result := 'TQuoteIBOWizard';
end;

function TQuoteIBOWizard.GetState: TWizardState;
begin
Result := [wsEnabled];
end;

end.