📄 jvqtranslator.pas
字号:
end;
tkInteger:
SetOrdProp(Obj, PropInfo, Elem.Items[I].IntValue);
tkClass:
begin
lObj := GetObjectProp(Obj, Elem.Items[I].Name);
TransProperties(lObj, Elem.Items[I]);
TransObject(lObj, Elem.Items[I]);
end;
end;
except
end;
end;
begin
if IsObject(Component.ClassType, cTJvTranslatorStrings) then
begin
TransVars;
Exit;
end;
try
//Transform properties
if not InSkipList(Component) then
TransProperties(Component, Elem);
//Transform childs
with Component do
for I := 0 to Elem.Items.Count - 1 do
begin
Ok := False;
for J := 0 to ComponentCount - 1 do
begin
S := LowerCase(Elem.Items[I].Name);
if AnsiSameText(Components[J].Name, S) then
begin
TranslateComponent(Components[J], Elem.Items[I]);
Ok := True;
Break;
end;
end;
if not Ok then
begin
PropInfo := GetPropInfo(Component, Elem.Items[I].Name, [tkUnknown, tkInteger, tkChar, tkEnumeration, tkFloat,
tkString, tkSet, tkClass, tkMethod, tkWChar, tkLString, tkWString,
tkVariant, tkArray, tkRecord, tkInterface, tkInt64, tkDynArray]);
if (PropInfo <> nil) and (PropInfo^.SetProc <> nil) and not InSkipList(Component, Elem.Items[I].Name) then
begin
Obj := GetObjectProp(Component, Elem.Items[I].Name);
if IsObject(Obj.ClassType, cTStrings) then
TransStrings(Obj, Elem.Items[I])
else
if IsObject(Obj.ClassType, cTTreeNodes) then
TransTreeNodes(Obj, Elem.Items[I])
else
if IsObject(Obj.ClassType, cTListItems) then
TransListItems(Obj, Elem.Items[I])
else
begin
TransProperties(Obj, Elem.Items[I]);
TransObject(Obj, Elem.Items[I]);
end;
end;
end;
end;
except
end;
end;
procedure TJvTranslator.Translate(const Form: TCustomForm);
var
J: Integer;
S: string;
lElem: TJvSimpleXMLElem;
begin
J := Pos('_', Form.Name);
if J = 0 then
S := Form.Name
else
S := Copy(Form.Name, 1, J - 1);
lElem := FindItemNamed(nil, S, True);
if lElem <> nil then
TranslateComponent(Form, lElem)
end;
function TJvTranslator.Translate(const Category, Item: string): string;
var
lElem: TJvSimpleXMLElem;
begin
Result := '';
lElem := FindItemNamed(nil, Category, True);
if lElem <> nil then
begin
lElem := FindItemNamed(lElem, Item, True);
if lElem <> nil then
begin
Result := lElem.Value;
if Result = '' then
Result := lElem.Properties.Value(cValue);
end;
end;
end;
procedure TJvTranslator.SkipClass(AClass: TClass);
begin
SkipProperty(AClass, '');
end;
procedure TJvTranslator.UnskipClass(AClass: TClass);
begin
UnskipProperty(AClass, '');
end;
function TJvTranslator.InSkipList(AClass: TClass): Boolean;
begin
Result := InSkipList(AClass, '');
end;
function TJvTranslator.InSkipList(Obj: TObject): Boolean;
begin
if Obj = nil then
Result := InSkipList(TObject(nil))
else
Result := InSkipList(Obj.ClassType);
end;
function TJvTranslator.InSkipList(Obj: TObject; const PropName: string): Boolean;
begin
if Obj = nil then
Result := InSkipList(TObject(nil), PropName)
else
Result := InSkipList(Obj.ClassType, PropName);
end;
function TJvTranslator.InSkipList(AClass: TClass; const PropName: string): Boolean;
var
I: Integer;
P: PSkipPropRec;
begin
Result := False;
if FSkipList <> nil then
for I := 0 to FSkipList.Count - 1 do
begin
P := PSkipPropRec(FSkipList[I]);
if (P^.AClass = AClass) or AClass.InheritsFrom(P^.AClass) then
begin
if ((PropName = '') and (P^.AProps.Count = 0)) or (P^.AProps.IndexOf(PropName) > -1) then
begin
Result := True;
if PropName = '' then
// move item to beginning of list since it is very likely that we want to access this class very soon
FSkipList.Move(I, 0);
Break;
end;
end;
end;
end;
procedure TJvTranslator.Translate(const Stream: TStream; const Form: TCustomForm);
begin
FXML.LoadFromStream(Stream);
Translate(Form);
end;
procedure TJvTranslator.TranslateString(const S: string);
var
Stream: TStringStream;
begin
Stream := TStringStream.Create(S);
try
Translate(Stream);
finally
Stream.Free;
end;
end;
procedure TJvTranslator.TranslateString(const S: string; const Form: TCustomForm);
var
Stream: TStringStream;
begin
Stream := TStringStream.Create(S);
try
Translate(Stream, Form);
finally
Stream.Free;
end;
end;
procedure TJvTranslator.TranslateScreenString(const S: string);
var
Stream: TStringStream;
begin
Stream := TStringStream.Create(S);
try
TranslateScreen(Stream);
finally
Stream.Free;
end;
end;
//=== { TJvTranslatorStrings } ===============================================
constructor TJvTranslatorStrings.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FList := THashedStringList.Create;
end;
destructor TJvTranslatorStrings.Destroy;
begin
FList.Free;
inherited Destroy;
end;
function TJvTranslatorStrings.Add(const Name: string; var Value: string): Integer;
begin
// (rom) AddObject? Strange.
Result := FList.AddObject(Name, TObject(@Value));
end;
function TJvTranslatorStrings.GetString(Index: Integer): string;
begin
Result := FList[Index];
end;
function TJvTranslatorStrings.IndexOf(const Name: string): Integer;
begin
Result := FList.IndexOf(Name);
end;
procedure TJvTranslatorStrings.SetString(Index: Integer; const Value: string);
begin
PString(FList.Objects[Index])^ := Value;
end;
function TJvTranslatorStrings.GetCount: Integer;
begin
Result := FList.Count;
end;
function TJvTranslatorStrings.GetValue(Index: Integer): string;
begin
if (Index >= 0) and (Index < Count) and (FList.Objects[Index] <> nil) then
Result := PString(FList.Objects[Index])^
else
Result := '';
end;
procedure TJvTranslator.SkipProperty(AClass: TClass; const PropName: string);
var
I: Integer;
P: PSkipPropRec;
begin
if FSkipList = nil then
FSkipList := TList.Create;
for I := 0 to FSkipList.Count - 1 do
if PSkipPropRec(FSkipList[I])^.AClass = AClass then
begin
P := PSkipPropRec(FSkipList[I]);
if PropName = '' then
P^.AProps.Clear // skip entire class
else
if P^.AProps.Count > 0 then // only add if the class is not skipped as a whole
P^.AProps.Add(PropName); // the list is sorted, so property name will only be added once
Exit;
end;
// class not found, so add new class record to list
New(P);
P^.AClass := AClass;
P^.AProps := TStringList.Create;
P^.AProps.Sorted := True;
if PropName <> '' then
P^.AProps.Add(PropName); // skip this property only
FSkipList.Add(P);
if AClass.InheritsFrom(TPersistent) then
RegisterClass(TPersistentClass(AClass));
end;
procedure TJvTranslator.UnskipProperty(AClass: TClass; const PropName: string);
var
I, J: Integer;
P: PSkipPropRec;
begin
if FSkipList <> nil then
begin
for I := 0 to FSkipList.Count - 1 do
if PSkipPropRec(FSkipList[I])^.AClass = AClass then
begin
P := PSkipPropRec(FSkipList[I]);
if PropName <> '' then
J := P^.AProps.IndexOf(PropName)
else
begin
J := -1;
P^.AProps.Clear;
end;
if J > -1 then
P^.AProps.Delete(J);
if P^.AProps.Count = 0 then
// remove the entry when there are no properties skipped or if this is a UnskipClass call
begin
P^.AProps.Free;
FSkipList.Delete(I);
Dispose(P);
end;
if FSkipList.Count = 0 then
FreeAndNil(FSkipList);
Break;
end;
end;
end;
procedure TJvTranslator.ClearSkipList;
var
I: Integer;
begin
if FSkipList <> nil then
begin
for I := 0 to FSkipList.Count - 1 do
begin
PSkipPropRec(FSkipList[I]).AProps.Free;
Dispose(PSkipPropRec(FSkipList[I]));
end;
FreeAndNil(FSkipList);
end;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvQTranslator.pas,v $';
Revision: '$Revision: 1.18 $';
Date: '$Date: 2005/02/06 14:06:17 $';
LogPath: 'JVCL\run'
);
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -