Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá amigos, uma boa tarde.
Novamente estou aqui, agora com uma dúvida, com a ajuda dos amigos, o listbox que estou desenvolvendo esta quase 100%, mas ainda acontece alguns bugs que estou vendo antes de levar para o cliente, pois nos colocamos no lugar do cliente, usando e abusando do software antes de levá-lo ao uso comercial.
O que acontece agora no meu listbox, na importação de todo o conteúdo de uma pasta, é que se tiver esse caracter ', ele da erro na importação, então vamos com duas perguntas.
Como tirar esse caracter do documento ao abrí-lo no listbox, e segundo, como substituir, palavras acentuadas por palavras que não usem acentos, exemplo ã por a, ó por o e assim por diante.
Abaixo segue o código de como esta o geral da importação de documentos para o banco de dados.
Só lembrando, se algum documento por exemplo for assim test'dd.doc ele da erro na importação por causa do '.
obrigado a todos
function RetiraExt(S: String): String;Var Extensao: Integer;begin Extensao := Pos('.', S); Delete(S, Extensao, 4); Result := S;end;function BrowseCallbackProc(hwnd: HWND; uMsg: UINT; lParam, lpData: LPARAM): Integer; stdcall;var Path: array[0..MAX_PATH] of Char;begin case uMsg of BFFM_INITIALIZED: begin SendMessage(hwnd, BFFM_SETSELECTION, 1, lpData); SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, lpData); end; BFFM_SELCHANGED: begin if SHGetPathFromIDList(Pointer(lParam), Path) then SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, Integer(@Path)); end; end; Result := 0;end;function SelectDir(hOwner: THandle; const Caption, InitialDir: string; const Root: WideString; ShowStatus: Boolean; out Directory: string): Boolean;var BrowseInfo: TBrowseInfo; Buffer: PChar; RootItemIDList, ItemIDList: PItemIDList; ShellMalloc: IMalloc; IDesktopFolder: IShellFolder; Eaten, Flags: LongWord; //LongInt;// Windows: Pointer;//^Integer;// Path: string;begin Result := False; Directory := ''; Path := InitialDir; if (Length(Path) > 0) and (Path[Length(Path)] = '\') then Delete(Path, Length(Path), 1); FillChar(BrowseInfo, SizeOf(BrowseInfo), 0); if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then begin Buffer := ShellMalloc.Alloc(MAX_PATH); try SHGetDesktopFolder(IDesktopFolder); IDesktopFolder.ParseDisplayName(hOwner, nil, PWideChar(Root), Eaten, RootItemIDList, Flags); with BrowseInfo do begin hwndOwner := hOwner; pidlRoot := RootItemIDList; pszDisplayName := Buffer; lpszTitle := PChar(Caption); ulFlags := BIF_RETURNONLYFSDIRS; if ShowStatus then ulFlags := ulFlags or BIF_STATUSTEXT; lParam := Integer(PChar(Path)); lpfn := BrowseCallbackProc; iImage := 0; end; // Make the browser dialog modal. Windows := DisableTaskWindows(hOwner); try ItemIDList := ShBrowseForFolder(BrowseInfo); finally EnableTaskWindows(Windows); end; Result := ItemIDList <> nil; if Result then begin ShGetPathFromIDList(ItemIDList, Buffer); ShellMalloc.Free(ItemIDList); Directory := Buffer; end; finally ShellMalloc.Free(Buffer); end; end;end;procedure TFImportar.btnprocurarClick(Sender: TObject);Var SearchFile: TSearchRec; FindResult: Integer; FilesDir, DirSelect: String;Const DefaultExt = '.';begin Listbox1.Clear; if SelectDir((Sender as TSpTBXButton).Parent.Handle, 'Procurar Diretório', FilesDir, '', False, DirSelect) then FilesDir := DirSelect; if FilesDir = '' then Exit; if FilesDir[Length(FilesDir)] <> '\' then FilesDir := FilesDir + '\'; if FilesDir <> '' then FindResult := FindFirst(FilesDir+DefaultExt, faArchive, SearchFile); try While FindResult = 0 do begin Application.ProcessMessages; ListBox1.Items.Add(UpperCase((RetiraExt(SearchFile.Name)))); //ListBox1.Items.Add((RetiraExt(SearchFile.Name))); FindResult := FindNext(SearchFile); end; finally FindClose(SearchFile) end;end;
Carregando comentários...