Login
Estamos no Facebook
Buscar
Quem está conectado
Há 26 usuários online :: 1 usuário cadastrado, Nenhum Invisível e 25 Visitantes :: 2 Motores de buscathiag0ms
[ Ver toda a lista ]
O recorde de usuários online foi de 468 em 1/3/2012, 10:43
Brasília
| |
Estamos no Twitter

Nossa Comunidade

Nosso Grupo

Últimos assuntos
Top dos mais postadores
| Marcos Guedes | ||||
| hugo | ||||
| alceu11 | ||||
| Julio | ||||
| m@r<3|o | ||||
| mfelis | ||||
| Tales Ruan | ||||
| Nelson Arcas | ||||
| _batmanvfp_ | ||||
| marcio |
Karaoke feito em FoxPro 2.6
23/5/2012, 11:45 por fabiomacarrao
Bom dia a todos. Desenvolvi um programa em FoxPro for windows 2.6 para karaoke. tenho mais de 2700 …
Comentários: 3
Estatísticas
Temos 4048 usuários registradosO último usuário registrado atende pelo nome de fabiomacarrao
Os nossos membros postaram um total de 14433 mensagens em 2047 assuntos
Arquivo INI
Página 1 de 1 • Compartilhe •
Arquivo INI
Encontrei uma ótima rotina para leitura de arquivo .ini no seguinte link:
mentalis.org/soft/class.qpx?id=6
Espero que seja útil aos colegas:
Obs: Precisei retirar a documentação pois o conteúdo estava grande para postar.
Não deixe de baixar o arquivo original:
[Você precisa estar registrado e conectado para ver este link.]
mentalis.org/soft/class.qpx?id=6
Espero que seja útil aos colegas:
- Código:
using System;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
namespace Org.Mentalis.Files
{
public class IniReader
{
// API declarations
[DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileIntA", CharSet = CharSet.Ansi)]
private static extern int GetPrivateProfileInt(string lpApplicationName, string lpKeyName, int nDefault, string lpFileName);
[DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileStringA", CharSet = CharSet.Ansi)]
private static extern int WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);
[DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileStringA", CharSet = CharSet.Ansi)]
private static extern int GetPrivateProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
[DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileSectionNamesA", CharSet = CharSet.Ansi)]
private static extern int GetPrivateProfileSectionNames(byte[] lpszReturnBuffer, int nSize, string lpFileName);
[DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileSectionA", CharSet = CharSet.Ansi)]
private static extern int WritePrivateProfileSection(string lpAppName, string lpString, string lpFileName);
public IniReader(string file)
{
Filename = file;
}
public string Filename
{
get
{
return m_Filename;
}
set
{
m_Filename = value;
}
}
public string Section
{
get
{
return m_Section;
}
set
{
m_Section = value;
}
}
public int ReadInteger(string section, string key, int defVal)
{
return GetPrivateProfileInt(section, key, defVal, Filename);
}
public int ReadInteger(string section, string key)
{
return ReadInteger(section, key, 0);
}
public int ReadInteger(string key, int defVal)
{
return ReadInteger(Section, key, defVal);
}
public int ReadInteger(string key)
{
return ReadInteger(key, 0);
}
public string ReadString(string section, string key, string defVal)
{
StringBuilder sb = new StringBuilder(MAX_ENTRY);
int Ret = GetPrivateProfileString(section, key, defVal, sb, MAX_ENTRY, Filename);
return sb.ToString();
}
public string ReadString(string section, string key)
{
return ReadString(section, key, "");
}
public string ReadString(string key)
{
return ReadString(Section, key);
}
public long ReadLong(string section, string key, long defVal)
{
return long.Parse(ReadString(section, key, defVal.ToString()));
}
public long ReadLong(string section, string key)
{
return ReadLong(section, key, 0);
}
public long ReadLong(string key, long defVal)
{
return ReadLong(Section, key, defVal);
}
public long ReadLong(string key)
{
return ReadLong(key, 0);
}
public byte[] ReadByteArray(string section, string key)
{
try
{
return Convert.FromBase64String(ReadString(section, key));
}
catch { }
return null;
}
public byte[] ReadByteArray(string key)
{
return ReadByteArray(Section, key);
}
public bool ReadBoolean(string section, string key, bool defVal)
{
return Boolean.Parse(ReadString(section, key, defVal.ToString()));
}
public bool ReadBoolean(string section, string key)
{
return ReadBoolean(section, key, false);
}
public bool ReadBoolean(string key, bool defVal)
{
return ReadBoolean(Section, key, defVal);
}
public bool ReadBoolean(string key)
{
return ReadBoolean(Section, key);
}
public bool Write(string section, string key, int value)
{
return Write(section, key, value.ToString());
}
public bool Write(string key, int value)
{
return Write(Section, key, value);
}
public bool Write(string section, string key, string value)
{
return (WritePrivateProfileString(section, key, value, Filename) != 0);
}
public bool Write(string key, string value)
{
return Write(Section, key, value);
}
public bool Write(string section, string key, long value)
{
return Write(section, key, value.ToString());
}
public bool Write(string key, long value)
{
return Write(Section, key, value);
}
public bool Write(string section, string key, byte[] value)
{
if (value == null)
return Write(section, key, (string)null);
else
return Write(section, key, value, 0, value.Length);
}
public bool Write(string key, byte[] value)
{
return Write(Section, key, value);
}
public bool Write(string section, string key, byte[] value, int offset, int length)
{
if (value == null)
return Write(section, key, (string)null);
else
return Write(section, key, Convert.ToBase64String(value, offset, length));
}
public bool Write(string section, string key, bool value)
{
return Write(section, key, value.ToString());
}
public bool Write(string key, bool value)
{
return Write(Section, key, value);
}
public bool DeleteKey(string section, string key)
{
return (WritePrivateProfileString(section, key, null, Filename) != 0);
}
public bool DeleteKey(string key)
{
return (WritePrivateProfileString(Section, key, null, Filename) != 0);
}
public bool DeleteSection(string section)
{
return WritePrivateProfileSection(section, null, Filename) != 0;
}
public ArrayList GetSectionNames()
{
try
{
byte[] buffer = new byte[MAX_ENTRY];
GetPrivateProfileSectionNames(buffer, MAX_ENTRY, Filename);
string[] parts = Encoding.ASCII.GetString(buffer).Trim('\0').Split('\0');
return new ArrayList(parts);
}
catch { }
return null;
}
private string m_Filename;
private string m_Section;
private const int MAX_ENTRY = 32768;
}
}
Obs: Precisei retirar a documentação pois o conteúdo estava grande para postar.
Não deixe de baixar o arquivo original:
[Você precisa estar registrado e conectado para ver este link.]
Última edição por Marcos Guedes em 20/7/2010, 14:20, editado 1 vez(es)
_________________
Marcos Guedes - Programador e desenvolvedor Web.
Convidado, seja nosso seguidor no Twitter:
twitter.com/programacaobras
Marcos Guedes- Webmaster

Re: Arquivo INI
Segue um exemplo de como utilizar a rotina:
Obs: Este exemplo foi retirado do próprio arquivo contido no seguinte link:
[Você precisa estar registrado e conectado para ver este link.]
- Código:
using System;
using System.Collections;
using Org.Mentalis.Files;
public class TestApp {
public static void Main() {
IniReader ini = new IniReader("c:\\test.ini");
ini.Write("Section1", "KeyString", "MyString");
ini.Write("Section1", "KeyInt", 5);
ini.Write("Section2", "KeyBool", true);
ini.Write("Section2", "KeyBytes", new byte[] {0, 123, 255});
ini.Write("Section3", "KeyLong", (long)123456789101112);
ini.Section = "Section1";
Console.WriteLine("String: " + ini.ReadString("KeyString"));
Console.WriteLine("Int: " + ini.ReadInteger("KeyInt", 0).ToString());
Console.WriteLine("Bool: " + ini.ReadBoolean("Section2", "KeyBool", false).ToString());
Console.WriteLine("Long: " + ini.ReadLong("Section3", "KeyLong", 0).ToString());
Console.WriteLine("Byte 1 in byte array: " + ini.ReadByteArray("Section2", "KeyBytes")[1].ToString());
ini.DeleteKey("Section2", "KeyBytes");
ini.DeleteSection("Section3");
IEnumerator e = ini.GetSectionNames().GetEnumerator();
while(e.MoveNext()) {
Console.WriteLine(e.Current);
}
Console.WriteLine("Press enter to continue...");
Console.ReadLine();
}
}
Obs: Este exemplo foi retirado do próprio arquivo contido no seguinte link:
[Você precisa estar registrado e conectado para ver este link.]
_________________
Marcos Guedes - Programador e desenvolvedor Web.
Convidado, seja nosso seguidor no Twitter:
twitter.com/programacaobras
Marcos Guedes- Webmaster

Página 1 de 1
Permissão deste fórum:
Você não pode responder aos tópicos neste fórum
Início
» Modificar TitleBar e Icone do Executavel.
» Criar atalho, SYS(2020) e Desktop
» Karaoke feito em FoxPro 2.6
» Como separar caminho do diretório?
» Utilizando PHPMailer
» Programador em Visual Foxpro
» Link PHP (Dúvida)
» Fundo do PROJETO Transparente??
» Minimizar , Maximizar e Restaurar
» Pivot Table no sql server
» Scroll EditBox Automatico
» Select Nexval do FoxPro no OracleXE
» Colocar gif na caixa do MESSAGEBOX ()
» Comparar Versões do programa.exe
» Menu lateral
» Fazer com que a tela do sistema assume a janela principal
» Trocar Palavra no Sistema
» invocar Dll em Xbase
» Fechar Porta Aberta