IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

Font Style dans fichier INI [Débutant]


Sujet :

C++Builder

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Février 2012
    Messages : 14
    Points : 16
    Points
    16
    Par défaut Font Style dans fichier INI
    Bonjour
    Que ce soit dans C++ Builder ou dans Delphi je n'arrive pas a écrire ou lire les informations concernant le Style d'une fonte dans un fichier INI. Quelqu'un sait comment?

  2. #2
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    salut,
    merci de poster ton code existant pour pouvoir t'aider
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Février 2012
    Messages : 14
    Points : 16
    Points
    16
    Par défaut
    Citation Envoyé par DjmSoftware Voir le message
    salut,
    merci de poster ton code existant pour pouvoir t'aider
    cdlt
    Voilà
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    	TIniFile * ini;
    	ini = new TIniFile( ChangeFileExt( Application->ExeName, ".INI" ) );
    	ini->WriteInteger( "Form", "Top", Top );
    	ini->WriteInteger( "Form", "Left", Left );
    	ini->WriteInteger( "Form", "Height", MyNotePadForm->Height );
    	ini->WriteInteger( "Form", "Width", MyNotePadForm->Width );
    	ini->WriteInteger( "Font", "Size", FontDialog->Font->Size );
    	ini->WriteString( "Font", "Name", FontDialog->Font->Name );
    	ini->WriteInteger( "Font", "Style", FontDialog->Font->Style.ToInt( ) );
    Je n'arrive pas à lire l'information contenu dans la dernière ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ini->WriteInteger( "Font", "Style", FontDialog->Font->Style.ToInt( ) );
    qui devrait être quelque chose comme : FontDialog->Font->Style...??? = ini->ReadInteger( "Font", "Style", 1); ( 1 pour gras)
    ...Je suppose

    Merci

  4. #4
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut,
    le probléme est que Style n'est pas de type integer

    pour la sauvegarde
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
     
    	TIniFile * ini;
    	ini = new TIniFile(ChangeFileExt(Application->ExeName, ".INI"));
    	ini->WriteInteger("Form", "Top", Label1->Top);
    	ini->WriteInteger("Form", "Left", Label1->Left);
    	ini->WriteInteger("Form", "Height", Label1->Height);
    	ini->WriteInteger("Form", "Width", Label1->Width);
    	ini->WriteInteger("Font", "Size", Label1->Font->Size);
    	ini->WriteString("Font", "Name", Label1->Font->Name);
    	ini->WriteInteger("Font", "Style", Label1->Font->Style.ToInt());
    	delete ini;
    et finalement pour la lecture
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
     
    	TIniFile * ini;
    	ini = new TIniFile(ChangeFileExt(Application->ExeName, ".INI"));
    	Label1->Top = ini->ReadInteger("Form", "Top", 0);
    	Label1->Left = ini->ReadInteger("Form", "Left", 0);
    	Label1->Height = ini->ReadInteger("Form", "Height", 0);
    	Label1->Width = ini->ReadInteger("Form", "Width", 0);
    	Label1->Font->Size = ini->ReadInteger("Font", "Size", 0);
    	Label1->Font->Name = ini->ReadString("Font", "Name", "");
            Label1->Font->Style=TFontStyles(byte(ini->ReadInteger("Font", "Style", 0)));
    	delete ini;
    	Repaint();
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Février 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Février 2012
    Messages : 14
    Points : 16
    Points
    16
    Par défaut
    Citation Envoyé par DjmSoftware Voir le message
    Salut,
    le probléme est que Style n'est pas de type integer
    voici un petit code en delphi qui permet de faire la conversion
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
     
    Uses TypInfo;
     
    Function StyleToString( styles: TFontStyles ): String;
    var
      style: TFontStyle;
    Begin
      Result := '[';
      For style := Low(style) To High(style) Do Begin
        If style IN styles Then Begin
          If Length(result) > 1 Then
            result := result + ',';
          result := result + GetEnumname( typeInfo(TFontStyle), Ord(style));
        End; { If }
      End; { For }
      Result := Result + ']';
    End; { StyleToString }
     
    Function StringToStyle( S: String ): TFontStyles;
    Var
      sl   : TStringlist;
      style: TfontStyle;
      i    : Integer;
    Begin
      Result := [];
      If Length(S) < 2 Then Exit;
     
      If S[1] = '[' Then
        Delete(S, 1, 1);
      If S[Length(S)] = ']' Then
        Delete(S, Length(S), 1);
     
      If Length(S) = 0 Then Exit;
     
      sl:= TStringlist.Create;
      try
        sl.commatext := S;
        For i := 0 To sl.Count-1 Do Begin
          try
            style := TFontStyle( GetEnumValue( Typeinfo(TFontStyle), sl[i]
    ));
            Include( Result, style );
          except
          end;
        End; { For }
      finally
        sl.free
      end;
    End; { StringToStyle }
     
    The problem with this is that the string can get quite long, so it is
    not an efficient storage format. A more compact text format would be
    the mentioned string of 0 and 1 digits:
     
    type
      EFontBitstringError = class(Exception);
    const
      FalseBitDigit = '0';
      TrueBitDigit  = '1';
      BitDigits : array [boolean] of char = (FalseBitDigit,TrueBitDigit);
     
    function StyleToBitstring( styles: TFontStyles ): String;
    var
      style: TFontStyle;
    begin
      SetLength(Result, Ord(High(Style)) - Ord(Low(Style)) + 1);
      for style := Low(style) to High(style) do
        Result[Ord(style) - Ord(Low(style)) + 1] :=
          BitDigits[style In Styles];
    end; { StyleToBitstring }
     
    function BitstringToStyle(const S: String): TFontStyles;
    var
      style: TFontStyle;
      N: Integer;
    begin
      Result := [];
      N:= 0;
      for style := Low(style) to High(style) do begin
        Inc(N);
        if (N > 0) and (N <= Length(S)) then
          case S[N] of
            FalseBitDigit: ; // nothing to do
            TrueBitDigit : Include(Result, style);
          else
            raise EFontBitstringError.CreateFmt(
              'Invalid character "%s" in bitstring "%s"!', [S[N], N]);
          end; {case}
      end; {for}
    end; {BitstringToStyle} Uses TypInfo;
     
    Function StyleToString( styles: TFontStyles ): String;
    var
      style: TFontStyle;
    Begin
      Result := '[';
      For style := Low(style) To High(style) Do Begin
        If style IN styles Then Begin
          If Length(result) > 1 Then
            result := result + ',';
          result := result + GetEnumname( typeInfo(TFontStyle), Ord(style));
        End; { If }
      End; { For }
      Result := Result + ']';
    End; { StyleToString }
     
    Function StringToStyle( S: String ): TFontStyles;
    Var
      sl   : TStringlist;
      style: TfontStyle;
      i    : Integer;
    Begin
      Result := [];
      If Length(S) < 2 Then Exit;
     
      If S[1] = '[' Then
        Delete(S, 1, 1);
      If S[Length(S)] = ']' Then
        Delete(S, Length(S), 1);
     
      If Length(S) = 0 Then Exit;
     
      sl:= TStringlist.Create;
      try
        sl.commatext := S;
        For i := 0 To sl.Count-1 Do Begin
          try
            style := TFontStyle( GetEnumValue( Typeinfo(TFontStyle), sl[i]
    ));
            Include( Result, style );
          except
          end;
        End; { For }
      finally
        sl.free
      end;
    End; { StringToStyle }
     
    The problem with this is that the string can get quite long, so it is
    not an efficient storage format. A more compact text format would be
    the mentioned string of 0 and 1 digits:
     
    type
      EFontBitstringError = class(Exception);
    const
      FalseBitDigit = '0';
      TrueBitDigit  = '1';
      BitDigits : array [boolean] of char = (FalseBitDigit,TrueBitDigit);
     
    function StyleToBitstring( styles: TFontStyles ): String;
    var
      style: TFontStyle;
    begin
      SetLength(Result, Ord(High(Style)) - Ord(Low(Style)) + 1);
      for style := Low(style) to High(style) do
        Result[Ord(style) - Ord(Low(style)) + 1] :=
          BitDigits[style In Styles];
    end; { StyleToBitstring }
     
    function BitstringToStyle(const S: String): TFontStyles;
    var
      style: TFontStyle;
      N: Integer;
    begin
      Result := [];
      N:= 0;
      for style := Low(style) to High(style) do begin
        Inc(N);
        if (N > 0) and (N <= Length(S)) then
          case S[N] of
            FalseBitDigit: ; // nothing to do
            TrueBitDigit : Include(Result, style);
          else
            raise EFontBitstringError.CreateFmt(
              'Invalid character "%s" in bitstring "%s"!', [S[N], N]);
          end; {case}
      end; {for}
    end; {BitstringToStyle}
    cdlt
    Merci pour cette réponse... Je reste surpris , car cela est si simple pour écrire dans le fichier INI avec cette ligne :

    FontDialog->Font->Style.ToInt( )...

    Résultat:
    [Font]
    Style =0 pour normal
    Style =1 pour gras
    Style =2 pour Italic

    Pourquoi le chemin inverse n'est pas aussi simple...??? Je trouve cela vraiment surprenant que cela ne soit pas possible...

  6. #6
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par 1bernard1 Voir le message
    Merci pour cette réponse... Je reste surpris , car cela est si simple pour écrire dans le fichier INI avec cette ligne :

    FontDialog->Font->Style.ToInt( )...

    Résultat:
    [Font]
    Style =0 pour normal
    Style =1 pour gras
    Style =2 pour oblique

    Pourquoi le chemin inverse n'est pas aussi simple...??? Je trouve cela vraiment surprenant que cela ne soit pas possible...
    un set est un ensemble de donnée donc pour la valeur par exemple 7 correspond à 1 et 2 et 4 ou fsBold << fsItalic << fsUnderline

    je viens de modifier le code de lecture
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  7. #7
    Membre chevronné
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Points : 2 187
    Points
    2 187
    Billets dans le blog
    1
    Par défaut
    Salut effectivement il y a plus simple avec ces deux fonctions en Delphi
    Code Delphi : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    //TFontStyles en integer
    function FontStylesToInt(Styles: TFontStyles): Integer;
    begin
      Result := byte(Styles)
    end;

    Code Delphi : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    // et son inverse
     
    function IntToFontStyles(Value: integer): TFontStyles;
    begin
      Result := TFontStyles(byte(Value))
    end;

    en c++ Builder
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    TIniFile * ini;
    	ini = new TIniFile(ChangeFileExt(Application->ExeName, ".INI"));
    	Label1->Top = ini->ReadInteger("Form", "Top", 0);
    	Label1->Left = ini->ReadInteger("Form", "Left", 0);
    	Label1->Height = ini->ReadInteger("Form", "Height", 0);
    	Label1->Width = ini->ReadInteger("Form", "Width", 0);
    	Label1->Font->Size = ini->ReadInteger("Font", "Size", 0);
    	Label1->Font->Name = ini->ReadString("Font", "Name", "");
        Label1->Font->Style=TFontStyles(byte(ini->ReadInteger("Font", "Style", 0)));
    	delete ini;
    	Repaint();
    cdlt
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 22/02/2009, 03h39
  2. Rechercher valeur dans fichier ini?
    Par jojo86 dans le forum Langage
    Réponses: 10
    Dernier message: 06/02/2009, 12h10
  3. Résultat d'une requête dans fichier ini
    Par bruno28 dans le forum VBA Access
    Réponses: 6
    Dernier message: 13/06/2007, 16h29
  4. Parametre dans fichier ini pour base fractionnée
    Par sunvialley dans le forum Access
    Réponses: 5
    Dernier message: 28/07/2006, 14h38
  5. [C#] Comment lire/ecrire dans fichier ini ?
    Par meli0207 dans le forum C#
    Réponses: 2
    Dernier message: 20/03/2006, 16h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo