Comment améliorer (pour que ca marche) ca ? :(

alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005 - 26 juil. 2004 à 10:27
alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005 - 26 juil. 2004 à 22:14
g une fonction :

function WriteReg(Key:string;Value:string;Data:string):boolean;
var registre : Tregistry; root:string;
begin
root:=SelPartText1(key);
key:=SelPartText2(key);
Registre:=TRegistry.Create;
case root of
'HKEY_CLASSES_ROOT' : Registre.RootKey:=HKEY_CLASSES_ROOT;
'HKEY_CURRENT_USER' : Registre.RootKey:=HKEY_CURRENT_USER;
'HKEY_LOCAL_MACHINE' : Registre.RootKey:=HKEY_LOCAL_MACHINE;
'HKEY_USERS' : Registre.RootKey:=HKEY_USERS;
'HKEY_CURRENT_CONFIG' : Registre.RootKey:=HKEY_CURRENT_CONFIG;
end;
try
Registre.OpenKey(key,true);
registre.WriteString(value,data);
except
messagedlg('Impossible d''accéder à la base des registres',mterror,[mbok],0);
end;
Registre.Free;
end;

SelPartText1 & 2 étant des fonction de sépartion de string !
le porb c la section case .. of !!!

13 réponses

slachz Messages postés 109 Date d'inscription lundi 21 avril 2003 Statut Membre Dernière intervention 1 janvier 2006
26 juil. 2004 à 10:55
d'abord tu peux simplifier ta function par function
WriteReg(Key, Value, Data:string):boolean; pour les parametres
sinon
case .. of accepte que des valeurs ordinales style ('a'..'z')
sinon la syntaxe est

case variable of
             valeur1 : parametre
             valeur2 : parametre
             
             valeurN : parametre
else
end;



et là t'oublie les : je crois que c'est pour ça ^^
0
slachz Messages postés 109 Date d'inscription lundi 21 avril 2003 Statut Membre Dernière intervention 1 janvier 2006
26 juil. 2004 à 10:58
zut ça prend pas les tabulations ! et g oubliés les ; derrieres les "instructions" (et pas les parametres).
0
alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005
26 juil. 2004 à 11:19
ok merci mais les : son en fin de ligne c la disposition de delphifr
ms en testant mon prog, il s'arrête à "case root of" ms je c po koi faire !
0
slachz Messages postés 109 Date d'inscription lundi 21 avril 2003 Statut Membre Dernière intervention 1 janvier 2006
26 juil. 2004 à 11:51
lol oki j'avais pas vus.
et le compilateur il te met koa comme message ?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005
26 juil. 2004 à 11:54
[Error] Project1.dpr(40): Ordinal type required
0
japee Messages postés 1727 Date d'inscription vendredi 27 décembre 2002 Statut Modérateur Dernière intervention 6 novembre 2021 8
26 juil. 2004 à 12:26
Laisse tomber Case of, alexis2015...

Ca ne prend que les expressions de type scalaire, les types chaîne sont interdits (voir l'aide de Delphi à ce sujet).

Pourquoi ne pas faire ainsi :

uses Registry;

function WriteReg(Key:string;Value:string;Data:string):boolean;
var registre: Tregistry; Root: string;
begin
  root:=SelPartText1(key);
  key:=SelPartText2(key);
  Registre:=TRegistry.Create;
  with Registre do
  begin
    try
      if Root = 'HKEY_CLASSES_ROOT' then RootKey := HKEY_CLASSES_ROOT;
      if Root = 'HKEY_CURRENT_USER' then Registre.RootKey:=HKEY_CURRENT_USER;
      if Root = 'HKEY_LOCAL_MACHINE' then Registre.RootKey:=HKEY_LOCAL_MACHINE;
      if Root = 'HKEY_USERS' then Registre.RootKey:=HKEY_USERS;
      if Root = 'HKEY_CURRENT_CONFIG' then Registre.RootKey:=HKEY_CURRENT_CONFIG;
      try
        OpenKey(key,true);
        WriteString(value,data);
      except
        messagedlg('Impossible d''accéder à la base des registres',mterror,[mbok],0);
      end;
    finally
      Free;
    end;
  end;
end;


C'est pas plus compliqué... ;)

Bonne prog' :-p
0
alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005
26 juil. 2004 à 12:29
ok merci bcp
0
alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005
26 juil. 2004 à 12:36
ca marche po !!! :sad)

[Error] Project1.dpr(40): Undeclared identifier: 'HKEY_CLASSES_ROOT'
[Error] Project1.dpr(41): Undeclared identifier: 'HKEY_CURRENT_USER'
[Error] Project1.dpr(42): Undeclared identifier: 'HKEY_LOCAL_MACHINE'
[Error] Project1.dpr(43): Undeclared identifier: 'HKEY_USERS'
[Error] Project1.dpr(44): Undeclared identifier: 'HKEY_CURRENT_CONFIG'

:sad) :sad) :sad)
0
alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005
26 juil. 2004 à 13:00
suggestion : registre.currentpath ? non ? ;)
0
japee Messages postés 1727 Date d'inscription vendredi 27 décembre 2002 Statut Modérateur Dernière intervention 6 novembre 2021 8
26 juil. 2004 à 13:55
Alors, tu t'en sors, alexis2015 ?

Voici ta fonction, j'ai gardé tes variables, je l'ai remaniée et testée avec 2 ComboBox et un Button.
Ca marche impeccable.

La fonction :

uses Registry;

function WriteReg(Root, Key, Value, Data: string): boolean;
var registre: Tregistry;
begin
  Result := False;
  Registre:=TRegistry.Create;
  with Registre do
  begin
    try
      if Root = 'HKEY_CLASSES_ROOT' then RootKey := HKEY_CLASSES_ROOT;
      if Root = 'HKEY_CURRENT_USER' then Registre.RootKey := HKEY_CURRENT_USER;
      if Root = 'HKEY_LOCAL_MACHINE' then Registre.RootKey := HKEY_LOCAL_MACHINE;
      if Root = 'HKEY_USERS' then Registre.RootKey := HKEY_USERS;
      if Root = 'HKEY_CURRENT_CONFIG' then Registre.RootKey := HKEY_CURRENT_CONFIG;
      try
        if OpenKey(Key, true) then
        begin
          WriteString(Value, Data);
          Result := True;
        end;
      except
        messagedlg('Impossible d''accéder à la base des registres',mterror,[mbok],0);
      end;
    finally
      Free;
    end;
  end;
end;


Appel de la fonction avec tes variables :

procedure TForm1.Button1Click(Sender: TObject);
var Racine, Cle, Valeur, Donnees: String;
begin
  Racine := SelPartText1(key);
  Cle := SelPartText2(key);
  Valeur := 'Ta valeur';
  Donnees := 'Tes données';
  if WriteReg(Racine, Cle, Valeur, Donnees)then
    ShowMessage('OK')
  else ShowMessage('Erreur');
end;


Vérification avec deux ComboBox et un Button :

procedure TForm1.Button1Click(Sender: TObject);
var Racine, Cle, Valeur, Donnees: String;
begin
  Racine := ComboBox1.Text;
  Cle := ComboBox2.Text;
  Valeur := Application.Title;
  Donnees := ExtractShortPathName(Application.ExeName);
  if WriteReg(Racine, Cle, Valeur, Donnees)then
    ShowMessage('OK')
  else ShowMessage('Erreur');
end;


Ca va aller ?

Bonne prog' :-p
0
alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005
26 juil. 2004 à 14:08
bo ca marche po,
oups g omi de dire que c'était une DLL ( quel con que je suis ) !
excuse!

g tester et ca marche tjs po ! [:'(]
0
alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005
26 juil. 2004 à 14:33
ok merci mais g un prob de compilation (cf + haut!)
evid mes fonction sont suivient de stdcall;
0
alexis2015 Messages postés 73 Date d'inscription mardi 8 avril 2003 Statut Membre Dernière intervention 24 juillet 2005
26 juil. 2004 à 22:14
au fit c'était tt con il fallait juste déclarer windows ds uses !!!
0
Rejoignez-nous