CnPack Forum


 
Subject: 脚本扩展专家如何实现这样的功能?
idseethis
新警察
Rank: 1



UID 39684
Digest Posts 0
Credits 6
Posts 2
点点分 6
Reading Access 10
Registered 2008-4-15
Status Offline
Post at 2008-4-15 12:32  Profile | Blog | P.M. 
脚本扩展专家如何实现这样的功能?

能不能在脚本扩展专家中,获取主窗体设计期间的实例?我想编写脚本,输出主窗体的所有字符串类型的数据
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6760
Posts 3556
点点分 6760
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-4-15 23:54  Profile | Blog | P.M. 
IDE主窗体的话用Application.MainForm就行。
设计期窗体本身,可用CnOtaGetRootComponentFromEditor(CnOtaGetCurrentFormEditor);
Top
idseethis
新警察
Rank: 1



UID 39684
Digest Posts 0
Credits 6
Posts 2
点点分 6
Reading Access 10
Registered 2008-4-15
Status Offline
Post at 2008-4-19 22:02  Profile | Blog | P.M. 
您好,我运行时遇到了一个问题,能看看吗?

Code:
{*******************************************************}
{                                                       }
{       Pascal Script Source File                       }
{       Run by RemObjects Pascal Script in CnWizards    }
{                                                       }
{       Generated by CnPack IDE Wizards                 }
{                                                       }
{*******************************************************}

program LangOutputter;

uses
  CnWizUtils, SysUtils, Classes, Forms, TypInfo;

procedure LogProp(Indent: Integer; const Parent, PropName, Kind, Value: string);
var
  Msg: string;
  i: Integer;
begin
  for i := 0 to Indent - 1 do
    Msg := Msg + '  ';
  if Parent <> '' then
    Msg := Msg + Parent + '.';
  Writeln(Format('%s%s: %s = %s', [Msg, PropName, Kind, Value]));
end;

procedure LogObject(Indent: Integer; const Parent: string; Inst: TObject);
var
  i: Integer;
  List: TStringList;
  Obj: TObject;
  Method: TMethod;
  S: string;
begin
  List := TStringList.Create;
  try
    GetPropList(Inst, tkAny, List);  <----------执行到这里是就报错了:Exception: Access violation at address 0895CB40 in module 'CnWizards_D11.dll'. Read of address 00000000 于 5.142
    for i := 0 to List.Count - 1 do
    begin
      try
        case PropType(Inst, List[i]) of
          tkUnknown:
            begin
              LogProp(Indent, Parent, List[i], 'tkUnknown', 'Unknown');
            end;
          tkInteger:
            begin
              LogProp(Indent, Parent, List[i], 'tkInteger', IntToStr(GetOrdProp(Inst, List[i])));
            end;
          tkChar:
            begin
              LogProp(Indent, Parent, List[i], 'tkChar', IntToStr(GetOrdProp(Inst, List[i])));
            end;
          tkEnumeration:
            begin
              LogProp(Indent, Parent, List[i], 'tkEnumeration', GetEnumProp(Inst, List[i]));
            end;
          tkFloat:
            begin
              LogProp(Indent, Parent, List[i], 'tkFloat', FloatToStr(GetFloatProp(Inst, List[i])));
            end;
          tkString:
            begin
              LogProp(Indent, Parent, List[i], 'tkString', GetStrProp(Inst, List[i]));
            end;
          tkSet:
            begin
              LogProp(Indent, Parent, List[i], 'tkSet', GetSetProp(Inst, List[i], True));
            end;
          tkClass:
            begin
              Obj := GetObjectProp(Inst, List[i]);
              LogProp(Indent, Parent, List[i], 'tkClass', '');
              if Parent <> '' then
                S := Parent + '.' + List[i]
              else
                S := List[i];
              if Obj <> nil then
                LogObject(Indent + 1, S, Obj);
            end;
          tkMethod:
            begin
              Method := GetMethodProp(Inst, List[i]);
              LogProp(Indent, Parent, List[i], 'tkMethod', '$' + IntToHex(Method.Code, 8));
            end;
          tkWChar:
            begin
              LogProp(Indent, Parent, List[i], 'tkWChar', IntToStr(GetOrdProp(Inst, List[i])));
            end;
          tkLString:
            begin
              LogProp(Indent, Parent, List[i], 'tkLString', GetStrProp(Inst, List[i]));
            end;
          tkWString:
            begin
              LogProp(Indent, Parent, List[i], 'tkWString', GetStrProp(Inst, List[i]));
            end;
          tkVariant:
            begin
              LogProp(Indent, Parent, List[i], 'tkVariant', '');
            end;
          tkArray:
            begin
              LogProp(Indent, Parent, List[i], 'tkArray', '');
            end;
          tkRecord:
            begin
              LogProp(Indent, Parent, List[i], 'tkRecord', '');
            end;
          tkInterface:
            begin
              LogProp(Indent, Parent, List[i], 'tkInterface', '');
            end;
          tkInt64:
            begin
              LogProp(Indent, Parent, List[i], 'tkInt64', Int64ToStr(GetInt64Prop(Inst, List[i])));
            end;
          tkDynArray:
            begin
              LogProp(Indent, Parent, List[i], 'tkDynArray', '');
            end;
        end;
      except
        ;
      end;                     
    end;
  finally
    List.Free;
  end;
end;

var
  MainForm: TObject;
begin
  MainForm := CnOtaGetRootComponentFromEditor(CnOtaGetCurrentFormEditor);
  LogObject(0, '', MainForm);
end.
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6760
Posts 3556
点点分 6760
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-4-20 11:15  Profile | Blog | P.M. 
看看MainForm得到的值是不是nil?
Top
 




All times are GMT++8, the time now is 2024-5-5 02:12

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.007985 second(s), 9 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP