Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 4th, 2012, 12:48 PM
Goaul Goaul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 1 Goaul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 34 m 55 sec
Reputation Power: 0
Load data from Csv file

Hi,
I dont know much from programming, but i want to learn atleast something.

I got some simple programs source and trying to improve it.

So how it works now
in CSV file there are such entrys
Code:
1;10-man-normal (maps without heroic mode)
2;25-man-normal (or heroics pre 3.2)
4;10-man heroic
8;25-man-heroic
15;Spawned in all maps

and function to load string from file:
Code:
procedure LoadStringListFromFile(List: TStrings; csvname: string); forward; export;

procedure LoadStringListFromFile(List: TStrings; csvname: string);
var
  i: integer;
  n: integer;
  F, s: string;
begin
  F := dmMain.ProgramDir+'CSV\'+csvname+'.csv';
  if FileExists(F) then
  begin
    List.LoadFromFile(F);
    List.BeginUpdate;
    try
      for i:=0 to List.Count - 1 do
      begin
        s := List[i];
        n := Pos(';', s);
        List[i] := midStr(s, n+1, MAX_ITEM_LENGTH);;
        List.Objects[i] := pointer( StrToInt(MidStr(s, 1, n-1)));
      end;
    finally
      List.EndUpdate;
    end;
  end;
end;


So it loads only strings no matter what integers inside and with (1 shl i) calculates integer depending what is checked and showing result in field.

Code:
procedure TUnitFlagsForm.btOKClick(Sender: TObject);
var
  i: integer;
  skip: boolean;
begin
  skip := false;
  FFlags := 0;
  for i := 0 to clbMain.Items.Count - 1 do
    if clbMain.Checked[i] then FFlags := FFlags or (1 shl i) else skip := true;
  if not skip then fflags := -1;  
end;

procedure TUnitFlagsForm.FormCreate(Sender: TObject);
begin
  dmMain.Translate.CreateDefaultTranslation(TForm(Self));
  dmMain.Translate.TranslateForm(TForm(Self));
end;

procedure TUnitFlagsForm.Load(What: string);
begin
  Caption := What;
  LoadStringListFromFile(clbMain.Items, What);
  if clbMain.Items.Count <= 16  then clbMain.Columns := 1;
end;

procedure TUnitFlagsForm.Prepare(Text: string);
var
  i: integer;
begin
  FFlags := StrToInt64Def(Text,0);
  for i := 0 to clbMain.Items.Count - 1 do
  begin
    if FFlags and (1 shl i) <> 0 then
      clbMain.Checked[i] := true;
  end;
end;

Result(image):
URL
http://img823.imageshack.us/img823/1839/84257356.jpg

What i want to change:
using (1 shl i) i can get the proper result if i click all first 4 checkboxes(result "15"), but if i want to use just 1 checkbox that should give the same value 15 without using any temp solution, it doesnt work(now gives 16).
As this funcion used not only for this 1 flag window, then it must be done some not hacky way.
So i decided best way would be, that depending what is checked, number would be loaded from csv file and shown in field and also in checkboxes.

Conditions:
+ If checked more then 1, then those are summed;
+ when loaded window, first should be checked csv file for such digit and if not then summing is applied to find what should be checked, for example, if in field used "3", then in window should be checked first 2 checkboxes. If "15" then checked is last checkbox);
+ if used like 40, what is not possible by summing even all, then none checkboxes should be checked;

If any could help me to get this done, would be really great

G

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Load data from Csv file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap