Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2003.06.09;
Скачать: [xml.tar.bz2];

Вниз

Сохранение шрифта в INI-файле   Найти похожие ветки 

 
Arch-vile   (2003-05-24 11:22) [0]

Собственно сабж. Как работать с ини-файлами я знаю.


 
Юрий Федоров   (2003-05-24 11:27) [1]

По полям - отдельно каждое


 
KSergey   (2003-05-24 14:40) [2]

А в чем проблема-то?! Проблемы-то в вопросе (равно как и его самого) нет...


 
Dimaz-z   (2003-05-24 16:17) [3]

Попробуй сохранить отдельно цвет, имя, высоту...


 
titnn   (2003-05-24 18:14) [4]

сохранение
procedure TMain.Font1Click(Sender: TObject);
procedure RegFont(int1:integer;str1:string;str2:string;i:integer);
begin
if i=1 then
MyReg.WriteInteger("FONT",str1,int1) else
MyReg.WriteString("FONT",str1,str2);
end;
begin
FontDialog.Font:=ChTr.Font;
FontDialog.Execute;
ChTr.Font:=FontDialog.Font;
With FontDialog do begin
RegFont(Font.Size,"Size","",1);
RegFont(0,"Name",Font.Name,0);
RegFont(Font.Color,"COLOR","",1);
if fsBold in font.Style then RegFont(1,"Bold","",1) else RegFont(0,"Bold","",1);
if fsItalic in font.Style then RegFont(1,"Italic","",1) else RegFont(0,"Italic","",1);
if fsUnderline in font.Style then RegFont(1,"Underline","",1) else RegFont(0,"Underline","",1);
if fsStrikeOut in font.Style then RegFont(1,"StrikeOut","",1) else RegFont(0,"StrikeOut","",1);
end;
end;


загрузка

ChTr.Color:=MyReg.ReadInteger("TREE","Color",ChTr.Color);
ChTr.Font.Name:=MyReg.ReadString("FONT","Name",ChTr.Font.Name);
ChTr.Font.Size:=MyReg.ReadInteger("FONT","Size",8);
ChTr.Font.Color:=MyReg.ReadInteger("FONT","Color",ChTr.Font.Color);
if MyReg.ReadInteger("FONT","Bold",0)=1 then Include(xx,fsBold) else Exclude(xx,fsBold);
if MyReg.ReadInteger("FONT","Italic",0)=1 then Include(xx,fsItalic)else Exclude(xx,fsItalic);
if MyReg.ReadInteger("FONT","Underline",0)=1 then Include(xx,fsUnderline)else Exclude(xx,fsUnderline);
if MyReg.ReadInteger("FONT","StrikeOut",0)=1 then Include(xx,fsStrikeOut)else Exclude(xx,fsStrikeOut);
ChTr.Font.Style:=xx;


 
Arch-vile   (2003-05-26 22:16) [5]

ключевое слово - в ини файле. Хотя данную идею я использую, т.е. преобразую под мои нужды


 
Arch-vile   (2003-05-26 23:21) [6]

Я не знаю, почему, но при записи
ini.WriteString("options","font name", SoneFont.Name);
компилятор ругается. в справке - TFont.Name - type string, тип несовместимый с остальными стрингами. Как обойти? не знаю

titnn © (24.05.03 18:14)
ты это из работающего проекта выдрал, или прям так в форуме и писал?


 
Дмитрий Белькевич   (2003-05-27 00:28) [7]

Из rx:

procedure TRxIniFile.WriteFont(const Section, Ident: string; Font: TFont);
begin
WriteString(Section, Ident, FontToString(Font));
end;

function FontToString(Font: TFont): string;
begin
with Font do
Result := Format("%s,%d,%s,%d,%s,%d", [Name, Size,
FontStylesToString(Style), Ord(Pitch), ColorToString(Color),
{$IFDEF RX_D3} Charset {$ELSE} 0 {$ENDIF}]);
end;


 
titnn   (2003-05-27 04:42) [8]

to Arch-vile
да , из рабочего проекта выдрал , все работает 100%


 
Arch-vile   (2003-05-27 08:59) [9]

2Дмитрий Белькевич
А расшифровать пожалуйста? Я не хочу ограничиватся простым копированием. + компилятор ругается на FontStylesToString(Style). Посмортел в справке - нет такой функции! Делфи 6.
При помощи справки я не смог разобратся с Format(...). Прошу объяснить.


 
Мое имя   (2003-05-27 09:16) [10]


> Посмортел в справке - нет такой функции!

значит rx не должна работать
гыгыгыгыгыгы


 
KoluChi   (2003-05-27 11:18) [11]

Посмотри
//-------------------------------------------------------------------------
procedure FontSaveToIni(Font: TFont; const IniFile, Section, Parameter: String);
var
FIni: TIniFile;
StyleCode: Integer;
begin
FIni:=TIniFile.Create(IniFile);
with FIni, Font do
try
WriteString(Section, Parameter + "_Name", Name);
WriteInteger(Section, Parameter + "_Charset", Charset);
WriteInteger(Section, Parameter + "_Color", Color);
WriteInteger(Section, Parameter + "_Size", Size);
StyleCode := GetIntByFontStyle(Style);
WriteInteger(Section, Parameter + "_Style", StyleCode);
finally
FIni.Free;
end;
end;
//-------------------------------------------------------------------------
procedure FontLoadFromIni(Font: TFont; const IniFile, Section, Parameter: String);
var
FIni: TIniFile;
StyleCode, ColorN, SizeN, CharsetN: Integer;
NameN: String;
begin
FIni:=TIniFile.Create(IniFile);
with FIni, Font do
try
CharsetN := ReadInteger(Section, Parameter + "_Charset", -1);
if CharsetN <> -1 then Charset := CharsetN;
ColorN := ReadInteger(Section, Parameter + "_Color", -1);
if ColorN <> - 1 then Color := ColorN;
NameN := ReadString(Section, Parameter + "_Name", "");
if NameN <> "" then Name := NameN;
SizeN := ReadInteger(Section, Parameter + "_Size", -1);
if SizeN <> -1 then Size := SizeN;
StyleCode := ReadInteger(Section, Parameter + "_Style", -1);
if StyleCode >= 0 then Style := GetFontStyleByInt(StyleCode);
finally
FIni.Free;
end;
end;
//-------------------------------------------------------------------------
function GetFontStyleByInt(StyleCode: Integer): TFontStyles;
var
NStyle: TFontStyles;
begin
NStyle := [];
if StyleCode >= 8 then
begin
NStyle := NStyle + [fsStrikeOut];
StyleCode := StyleCode - 8;
end;
if StyleCode >= 4 then
begin
NStyle := NStyle + [fsUnderline];
StyleCode := StyleCode - 4;
end;
if StyleCode >= 2 then
begin
NStyle := NStyle + [fsItalic];
StyleCode := StyleCode - 2;
end;
if StyleCode >= 1 then
NStyle := NStyle + [fsBold];
Result := NStyle;
end;
//-------------------------------------------------------------------------
function GetIntByFontStyle(Style: TFontStyles): Integer;
var
StyleCode: Integer;
begin
StyleCode := 0;
if fsBold in Style then StyleCode := StyleCode + 1;
if fsItalic in Style then StyleCode := StyleCode + 2;
if fsUnderline in Style then StyleCode := StyleCode + 4;
if fsStrikeOut in Style then StyleCode := StyleCode + 8;
Result := StyleCode;
end;
//-------------------------------------------------------------------------


 
Arch-vile   (2003-05-27 15:53) [12]

1. Так, rx нам нафиг не нужен. Забудем про него.
2. КАК у вас может работать ini.ReadString("options","font name", "MS Sans Serif");???? Объясните пожалуйста!
Написано:
NameN := ReadString(Section, Parameter + "_Name", "");
Вставляю эту строчку в код (естественно, меняя названия переменных под свои) - глючит. Комментирую - работает.
WriteString(Section, Parameter + "_Name", Name);
КАК ЭТО У ВАС РАБОТАЕТ??? Font.Name = type string! Оно не совместимо с остальными строковыми типами! ДЕЛФИ 6.
ЗЫ Юрий Зотов, ответь :)


 
Юрий Федоров   (2003-05-27 16:03) [13]

Приведи код полностью. Строка
ini.WriteString("options","font name", SoneFont.Name);должна компилироваться нормально в D6


 
Sandman25   (2003-05-27 16:04) [14]

Я тоже сталкивался с чем-то похожим - при присваивании Font.Name он не менялся (проверял в отладчике). Я думаю, Windows может проигнорировать присваивание, если установленного шрифта нет (и нечем его заменить, либо вместо него подставляется тот шрифт, который и был до присваивания). Тоже Delphi6.


 
Arch-vile   (2003-05-27 16:21) [15]


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
try
ini.WriteInteger("Options", "Difficulty", Level);
ini.WriteInteger("Options", "Fone Color", Coler[0, 0]);
ini.WriteInteger("Options", "First Line Color", Coler[1, 0]);
ini.WriteInteger("Options", "Second Line Color", Coler[2, 0]);
ini.WriteInteger("Options", "Third Line Color", Coler[3, 0]);
ini.WriteInteger("Options", "Fourth Line Color", Coler[4, 0]);
ini.WriteInteger("Options", "Fifth Line Color", Coler[5, 0]);
ini.WriteInteger("Options", "First Line XP", Coler[1, 1]);
ini.WriteInteger("Options", "Second Line XP", Coler[2, 1]);
ini.WriteInteger("Options", "Third Line XP", Coler[3, 1]);
ini.WriteInteger("Options", "Fourth Line XP", Coler[4, 1]);
ini.WriteInteger("Options", "Fifth Line XP", Coler[5, 1]);
ini.WriteString("Options", "Font Name", BtnFont.Name);
//комментирую эту строку ^ и все работает. Если нет, при закрытии выдает ошибку Access Violation at address ...
ini.WriteBool("Options", "Like XP", ButtonXP);
finally
ini.Free;
end;
end;

Так лучше?
Не компилируется. Я же говорю, посмотрите хелп по TFont.Name


 
Sandman25   (2003-05-27 16:30) [16]

with tinifile.create("111") do
writestring(font.name,font.name,font.name);
У меня даже это компилируется... Может у Вас включена директива коротких строк?


 
Юрий Федоров   (2003-05-27 16:32) [17]

Что такое BtnFont, где он создется и разрушается ?


 
Arch-vile   (2003-05-27 16:38) [18]

2Юрий Федоров
var BtnFont: TFont;

2Sandman25
ini:=TIniFile.create("C:\myini.ini");
Что такое директива короких строк?


 
Skier   (2003-05-27 16:39) [19]

>Arch-vile © (27.05.03 16:38)
var BtnFont: TFont; И всё что ли ?! Супербизон !


 
Юрий Федоров   (2003-05-27 16:46) [20]

Да уж. Объекты неплохо перед использованием создавать


 
Sandman25   (2003-05-27 16:58) [21]

Arch-vile
Наберите $H и нажмите F1


 
Arch-vile   (2003-05-27 20:35) [22]

Вот %^&%$$#!!! TFont - это же объект! Кстати, я сначала сам это допер, а потом уже и здесь увидел. Получается, что это как запись типа, или массив (я почему-то так думал). Уже работает.



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2003.06.09;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.5 MB
Время: 0.01 c
6-26646
Дмитрий К.К.
2003-04-07 11:59
2003.06.09
Поиск файла в Интернете


8-26622
SDS
2003-02-21 14:27
2003.06.09
Как уменьшить размер TBitmap


1-26520
Project111
2003-05-27 17:19
2003.06.09
Создать документ Word


1-26602
Dimedrol
2003-05-28 15:12
2003.06.09
Access violation ... in module rtl60.bpl


4-26849
-Sesh-
2003-04-08 15:47
2003.06.09
Как узнать коды кнопок если программа не активна





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский