Raison d'un access vilation sur end. ?

Résolu
timbuk Messages postés 74 Date d'inscription vendredi 6 juin 2008 Statut Membre Dernière intervention 26 février 2012 - 26 févr. 2012 à 18:08
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 - 9 mars 2012 à 03:35
Salut,
J'ai un "petit" soucis: lors du lancement de mon application, j'ai un access violation sur la ligne end. de mon fichier .dpr (qui contient les Application.Initialize;, CreateForm(), ...)
Malgré mes recherches, je ne sais pas pourquoi cela se produit.
Merci d'avance

3 réponses

timbuk Messages postés 74 Date d'inscription vendredi 6 juin 2008 Statut Membre Dernière intervention 26 février 2012
26 févr. 2012 à 20:46
Bon en fait c'est d'une stupidité impardonnable, juste le S := ''; qui faisait tout foirer.
Voila. C'est marrant combien il est plus facile de résoudre ses problèmes tout seul une fois qu'on a ouvert un topic...
3
timbuk Messages postés 74 Date d'inscription vendredi 6 juin 2008 Statut Membre Dernière intervention 26 février 2012
26 févr. 2012 à 18:46
(Je trouve pas la fonction éditer, ça n'existe pas sur ce forum?)
Il s'agissait en fait d'un bout de code sur le FormShow qui prend un access violation...
voici le code raccourci):

TExplodeArray = array of String;

function Explode(const cSeparator, vString: String): TExplodeArray;
var
  i: Integer;
  S: String;
begin
  //S := vString;
  S := '';
  SetLength(Result, 0);
  i := 0;
  while Pos(cSeparator, S) > 0 do begin
    SetLength(Result, Length(Result) +1);
    Result[i] := Copy(S, 1, Pos(cSeparator, S) -1);
    Inc(i);
    S := Copy(S, Pos(cSeparator, S) + Length(cSeparator), Length(S));
  end;
  SetLength(Result, Length(Result) +1);
  Result[i] := Copy(S, 1, Length(S));
end;

var
  tableauTemp1: TExplodeArray;
  tableauTemp2: TExplodeArray;

//[...]

  tableauTemp1 := Explode('_', DirName);
  if Length(tableauTemp1) > 0 then
  begin
    EditVerInstalledGame.Text := tableauTemp1[1]+'.'+tableauTemp1[2]+'.'+tableauTemp1[3];
    EditVerInstalledTrad.Text := tableauTemp1[4];
end;
0
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
9 mars 2012 à 03:35
Halalala,


une méthode magique pour toi :

crée cette unité et enregistre la dans ton dossier Delphi\Lib

Code Delphi :

unit CSVList;

interface

uses
  Windows, SysUtils, Classes;

type
  TStringList = class(Classes.TStringList)
  private
    fNoProtect: boolean;
    function getCSV: string;
    procedure setCSV(const Value: string);
  public
    property CSV: string read getCSV write setCSV;
    constructor CreateAsCSV(aProtector,aDelimiter: char); reintroduce;
  end;

implementation

{ TStringList }

constructor TStringList.CreateAsCSV(aProtector, aDelimiter: char);
begin
  inherited;
  fNoProtect :aProtector #0;
  if not fNoProtect then
    QuoteChar := aProtector;
  Delimiter := aDelimiter;
  StrictDelimiter := true;
end;

function TStringList.getCSV: string;
var N,L: integer;
begin
  L := count-1;
  result := '';
  for N := 0 to L do
  begin
    if fNoProtect then
      result := result + strings[N]
    else
      result := result + quoteChar + strings[N] + quoteChar;

    if N < L then
      result := result + Delimiter;
  end;
end;

procedure TStringList.setCSV(const Value: string);
begin
  delimitedText := Value;
end;

end.




Il suffira de l'ajouter dans les Uses de ton projet aprés l'unité Classes pour beneficier de TStringList supportant rapidement le format CSV.

à utiliser comme suis :

Code Delphi :
uses {....,} Classes,{ ....,} CSVList;

{...}

procedure BlaBlaBla;
var TSL: TStringList;
begin
  TSL := TStringList.CreateAsCSV(#0, '_');
  try
    TSL.CSV := DirName; // 1_2_3_FR
    if TSL.Count=4 then
    begin
      EditVerInstalledTrad.Text := TSL[3]; // FR
      TSL.Delete(3);
      TSL.Delimiter := '.';
      EditVerInstalledGame.Text := TSL.CSV; // 1.2.3
    end;
  finally
    TSL.Free;
  end;
end;


________________________________________________________
besoin de câbles audio, vidèo, informatique pas cher ?
0
Rejoignez-nous