Hej Ulrik
Jeg bruger selv din metode, - her er basis delen af den.
Oversættelser ligger i en database tabel.
mvh Thomas Riedel
function ValStr(compname, phrase : string) : string;
var s : string;
begin
s := dmdb.sqlfunc('select '+natlan+', name from languages where name =
'+quotedstr(compname));
if dmdb.query1.fields[1].asstring = '' then
begin
dmdb.dosql('Insert into languages (name, '+
natlan+') values ('+
quotedstr(compname)+', '+
quotedstr(phrase)+')' );
end else
if s = '' then
begin
dmdb.dosql('update languages set '+
natlan+' = '+
quotedstr(phrase)+' where '+
'name = '+quotedstr(compname))
end;
if s = '' then s := phrase;
dmdb.dosql('update languages set '+
' ok = 1'+
' where '+
' name = '+quotedstr(compname));
result := s;
end;
procedure setLanguage;
var i,j,k : integer;
c : tcomponent;
f : tform;
begin
natlan := frmsetup.lblanguage.caption;
counter := 0;
for i := 0 to application.Componentcount-1 do
if application.components[i] is tform then
with application.components[i] as tform do
begin
caption := valstr(name, caption);
f := tform(application.components[i]);
for j := 0 to f.componentcount-1 do
begin
c := components[j];
{if c.tag = 100 then exit;
if c.tag=0 then c.tag := 100;}
if c is tdbgrid then
with tdbgrid(c) do
hint := valstr(F.name+'.'+c.Name, hint);
if c is tgroupbox then
with c as tgroupbox do
begin
caption := valstr(f.Name+'.'+c.Name, caption);
end else
if c is tradiogroup then
with c as tradiogroup do
begin
caption := valstr(f.Name+'.'+c.Name, caption);
for k := 0 to items.count-1 do
items[k] := valstr(f.Name+'.'+c.Name+inttostr(k), items[k]);
end else
if c is tbitbtn then
with c as tbitbtn do
begin
caption := valstr(f.Name+'.'+c.Name, caption);
hint := valstr(f.Name+'.'+c.Name+'.hint', hint);
end else
if c is tbutton then
with c as tbutton do
begin
caption := valstr(f.Name+'.'+c.Name, caption);
hint := valstr(f.Name+'.'+c.Name+'.hint', hint);
end else
if c is tedit then
with c as tedit do
begin
hint := valstr(f.Name+'.'+c.Name+'.hint', hint);
end else
if c is tspeedbutton then
with c as tspeedbutton do
begin
caption := valstr(f.Name+'.'+c.Name, caption);
hint := valstr(f.Name+'.'+c.Name+'.hint', hint);
end else
if c is tcheckbox then
with c as tcheckbox do
begin
caption := valstr(f.Name+'.'+c.Name, caption);
end else
if c is tmenuitem then
with c as tmenuitem do
begin
if tag = 0 then
begin
caption := valstr(f.Name+'.'+c.Name, caption);
hint := valstr(f.Name+'.'+c.Name+'.hint', hint);
end;
end else
if c is ttabset then
with c as ttabset do
begin
for k := 0 to tabs.count-1 do
tabs[k] := valstr(f.Name+'.'+c.Name+inttostr(k), tabs[k]);
hint := valstr(f.Name+'.'+c.Name+'.hint', hint);
end else
if c is ttable then
with c as ttable do
begin
if tag <> 1001 then
for k := 0 to FieldCount -1 do
with fields[k] do
if visible then
displaylabel := valstr(f.Name+'.'+fields[k].Name, displaylabel);
end else
if c is tquery then
with c as tquery do
begin
for k := 0 to FieldCount -1 do
with fields[k] do
if visible then
displaylabel := valstr(f.Name+'.'+fields[k].Name, displaylabel);
end else
if c is tlabel then
with c as tlabel do
begin
if tag = 0 then
//IF (CAPTION <> '')
// AND NOT (CAPTION[1] IN ['0'..'9'])
caption := valstr(f.Name+'.'+c.Name, caption);
if (f = frmsetup) and (c = frmsetup.label1) then
c := c;
end else
if c is tqrlabel then
with c as tqrlabel do
begin
caption := valstr(f.Name+'.'+c.Name, caption);
{caption := v(caption);}
end;
if c is tdbnavigator then
with c as tdbnavigator do
begin
hint := valstr(f.Name+'.'+c.Name+'hint', hint);
for k := 0 to hints.count-1 do
hints[k] := valstr(f.Name+'.'+c.Name+'h'+inttostr(k), hints[k]);
{caption := v(caption);}
end;
end;
end;
end;
"Ulrik Vadstrup" <blackend@FJERNMIGblackend.dk> skrev i en meddelelse
news:c0olqn$2m64$1@news.cybercity.dk...
> Hejsa folkens - jeg har lidt af et projekt igang.
>
> Jeg vil lave en component der kan slå en oversættelse op i en DB.
>
> Meningen er at den skal droppes på en form, så skal den runtime slå alle
> TCaption, TCheckBox osv. op i dabasen og hente oversættelsen.
>
> Jeg har tænkt mig at tæller alle componenterne på "owner" til min
component.
> og så bruge en lang case sætning
>
> Hvordan udfører jeg det rent praktisk i min component kode.
>
> Noget alla
>
> For i := 0 to Owner.components.count do
> if Owner.component[i] is TPanel then
> begin
> end;
>
> osv osv.....
>
> Hvordan er den rigtige syntax - når min component skal kunne placers på
> TPanel, TForm, TTabpage osv.
>
> Findes der måske allerede noget ligende som freeware.
>
> --
> Ulrik Vadstrup
> Send gratis SMS med din PC
>
http://www.blackend.dk - se under download nederst.
>
>