Changeset 8 for trunk/UFormImport.pas
- Timestamp:
- Apr 21, 2016, 1:12:45 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UFormImport.pas
r6 r8 14 14 15 15 TFormImport = class(TForm) 16 ButtonLoadFromFile: TButton; 16 17 ButtonImport: TButton; 18 ComboBoxDataFormat: TComboBox; 19 Label1: TLabel; 17 20 Memo1: TMemo; 21 OpenDialog1: TOpenDialog; 18 22 procedure ButtonImportClick(Sender: TObject); 23 procedure ButtonLoadFromFileClick(Sender: TObject); 19 24 private 20 { private declarations } 25 procedure ImportMediaWiki; 26 procedure ImportCSV; 21 27 public 22 28 { public declarations } … … 55 61 56 62 procedure TFormImport.ButtonImportClick(Sender: TObject); 63 begin 64 if ComboBoxDataFormat.ItemIndex = 0 then ImportCSV; 65 if ComboBoxDataFormat.ItemIndex = 1 then ImportMediaWiki; 66 end; 67 68 procedure TFormImport.ButtonLoadFromFileClick(Sender: TObject); 69 begin 70 if OpenDialog1.Execute then 71 Memo1.Lines.LoadFromFile(OpenDialog1.FileName); 72 end; 73 74 procedure TFormImport.ImportMediaWiki; 57 75 var 58 76 I: Integer; 59 77 Line: string; 60 78 AcronymName: string; 61 Acronym Description: string;79 AcronymMeaning: string; 62 80 AddedCount: Integer; 63 81 Acronym: TAcronym; … … 74 92 end; 75 93 if Copy(Line, 1, 1) = ':' then begin 76 Acronym Description:= Trim(Copy(Line, 2, Length(Line)));77 if AcronymName <> ''then begin94 AcronymMeaning := Trim(Copy(Line, 2, Length(Line))); 95 if (AcronymName <> '') and (AcronymMeaning <> '') then begin 78 96 Acronym := FormMain.AcronymDb.Acronyms.SearchByName(AcronymName); 79 97 if not Assigned(Acronym) then begin … … 82 100 FormMain.AcronymDb.Acronyms.Add(Acronym); 83 101 end; 84 Meaning := Acronym.Meanings.SearchByName(Acronym Description);102 Meaning := Acronym.Meanings.SearchByName(AcronymMeaning); 85 103 if not Assigned(Meaning) then begin 86 104 Meaning := TAcronymMeaning.Create; 87 Meaning.Name := Acronym Description;105 Meaning.Name := AcronymMeaning; 88 106 Meaning.Acronym := Acronym; 89 107 Acronym.Meanings.Add(Meaning); … … 97 115 end; 98 116 117 procedure TFormImport.ImportCSV; 118 var 119 I: Integer; 120 Line: string; 121 Columns: TStringList; 122 Acronym: TAcronym; 123 Meaning: TAcronymMeaning; 124 AcronymName: string; 125 AcronymMeaning: string; 126 AcronymDescription: string; 127 AddedCount: Integer; 128 begin 129 AddedCount := 0; 130 Columns := TStringList.Create; 131 Columns.StrictDelimiter := True; 132 for I := 0 to Memo1.Lines.Count - 1 do begin 133 Line := Trim(Memo1.Lines[I]); 134 Columns.DelimitedText := Line; 135 if Columns.Count > 0 then AcronymName := Trim(Columns[0]) 136 else AcronymName := ''; 137 if Columns.Count > 1 then AcronymMeaning := Trim(Columns[1]) 138 else AcronymMeaning := ''; 139 if Columns.Count > 2 then AcronymDescription := Trim(Columns[2]) 140 else AcronymDescription := ''; 141 if (AcronymName <> '') and (AcronymDescription <> '') then begin 142 Acronym := FormMain.AcronymDb.Acronyms.SearchByName(AcronymName); 143 if not Assigned(Acronym) then begin 144 Acronym := TAcronym.Create; 145 Acronym.Name := AcronymName; 146 FormMain.AcronymDb.Acronyms.Add(Acronym); 147 end; 148 Meaning := Acronym.Meanings.SearchByName(AcronymDescription); 149 if not Assigned(Meaning) then begin 150 Meaning := TAcronymMeaning.Create; 151 Meaning.Name := AcronymMeaning; 152 Meaning.Description := AcronymDescription; 153 Meaning.Acronym := Acronym; 154 Acronym.Meanings.Add(Meaning); 155 Inc(AddedCount) 156 end; 157 end; 158 end; 159 Columns.Free; 160 if AddedCount > 0 then FormMain.AcronymDb.Modified := True; 161 ShowMessage(Format('Imported %d new acronyms.', [AddedCount])); 162 end; 163 99 164 end. 100 165
Note:
See TracChangeset
for help on using the changeset viewer.